Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: PHP Include... Again!

  1. #1
    Join Date
    Aug 2005
    Posts
    174
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default PHP Include... Again!

    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.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You need to use an output buffer.
    PHP Code:
    <?php
    ob_start
    ();
    include(
    "http://www.affiliate.com/page.php");
    $inc ob_get_contents();
    ob_end_clean();
    ?>
    You can then use str_replace() and friends on $inc, which is a string containing the page, before echoing it.
    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!

  3. #3
    Join Date
    Aug 2005
    Posts
    174
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    use str_replace() and friends on $inc, which is a string containing the page, before echoing it.

    $inc_new = str_replace("the text i want changing", "what i am changing it to?", $inc);


    I'm not sure what you mean by
    Quote Originally Posted by Twey
    and friends on $inc.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    That's the one. Although you might as well reuse $inc, unless you'll want the original back again.
    Quote Originally Posted by nikomou
    I'm not sure what you mean by
    Quote Originally Posted by Me
    and friends on $inc.
    str_replace() and the other string functions (str_split(), substr(), &c.) as needed.
    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!

  5. #5
    Join Date
    Aug 2005
    Posts
    174
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    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"]);

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    setcookie("tracking", $tracking, time()+31536000);
    $tracking = $_GET['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.
    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!

  7. #7
    Join Date
    Aug 2005
    Posts
    174
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    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

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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!

  9. #9
    Join Date
    Aug 2005
    Posts
    174
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    i tried that,

    the cookie still gets deleted if there is no ?tracking=xxxx

    and again, no included page.

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •