Hey Guys,
Just wondering if its possible to do a "find and replace" on the content pulled in from a php include...??
I'm including some pages into my site (from an affiliate) but would like to change a bit of the code...
Cheers.
Hey Guys,
Just wondering if its possible to do a "find and replace" on the content pulled in from a php include...??
I'm including some pages into my site (from an affiliate) but would like to change a bit of the code...
Cheers.
You need to use an output buffer.
You can then use str_replace() and friends on $inc, which is a string containing the page, before echoing it.PHP Code:<?php
ob_start();
include("http://www.affiliate.com/page.php");
$inc = ob_get_contents();
ob_end_clean();
?>
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Originally Posted by Twey
$inc_new = str_replace("the text i want changing", "what i am changing it to?", $inc);
I'm not sure what you mean byOriginally Posted by Twey
That's the one. Although you might as well reuse $inc, unless you'll want the original back again.
str_replace() and the other string functions (str_split(), substr(), &c.) as needed.Originally Posted by nikomou
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Cheers for that.
Could you just quickly tell me what is wrong with the following code? (this has nothing to do with editing the accual page i am including...)
(before the Head)
setcookie("tracking", $tracking, time()+31536000);
$tracking = $_GET['tracking'];
(in the body)
if (isset($_COOKIE["tracking"]))
include ("http://www.affiliatewebsite.com/?tracking=" . $_COOKIE["tracking"]);
You've used $tracking before declaring it. The second argument to setcookie() will always be blank, and will throw a warning with E_STRICT error reporting.Code:setcookie("tracking", $tracking, time()+31536000); $tracking = $_GET['tracking'];
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
ok, i've swaped these over
$tracking = $_GET['tracking'];
setcookie("tracking", $tracking, time()+31536000);
if i use ?tracking=adwords after the url, a cookie is made, and everything works, but if i refresh the page, removing the ?tracking=adwords, the cookie gets deleted!
How can I stop this from happening??
The include also doesnt show if there is no "?tracking=xxxx" after the url
The include doesn't show because the cookie doesn't get set. The cookie doesn't get set because you set a blank cookie if $_GET['tracking'] isn't set. Just use an if(isset($_GET['tracking'])) before the setcookie() call.
Last edited by Twey; 11-02-2005 at 09:34 PM.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
i tried that,
the cookie still gets deleted if there is no ?tracking=xxxx
and again, no included page.
Peculiar... please post your full code (inside [php] or [code] tags).
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Bookmarks