String manipulation problem

Discussion in 'PHP' started by juicytuna, Sep 12, 2007.

  1. #1
    I have a url string with some text appended on the end which I'm trying to remove:

    www.domain.com/dns/domain_approve.html?DOMAIN_NAME=anotherdomain.com&id_code=6317e2548dbb4876518de052671f77e7.If for some reason the above link does not work, please go to:
    Code (markup):
    I am trying to remove ".If for some reason the above link does not work, please go to:", but for some reason none of the methods I tried work. I've tried str_replace, substr and explode by period and removing the relevant segment but nothing works. Using substr has strange behaviour in that it only removes characters from the URL part of the string even if I specify it to start from the end!

    Spent a couple of hours on this already and it's doing my head in. Is there a bug in php 5 that I should be aware of?
     
    juicytuna, Sep 12, 2007 IP
  2. DopeDomains

    DopeDomains Guest

    Messages:
    207
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I can't see why this woulnd't work:
    
    $str="www.domain.com/dns/domain_approve.html?DOMAIN_NAME=anotherdomain.com&id_code=6317e2548dbb4876518de052671f77e7.If for some reason the above link does not work, please go to:";
    $newStr=substr($str, 0, strpos($str, ".If for"));
    print($newStr);
    
    PHP:
    EDIT: Tested, it does work.

    -Jason
     
    DopeDomains, Sep 12, 2007 IP
  3. juicytuna

    juicytuna Active Member

    Messages:
    92
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    95
    #3
    Thanks, that works fine :) I made a mistake in making the wrong assumptions about the order of strings in an array.
     
    juicytuna, Sep 12, 2007 IP