New line from no where?

Discussion in 'PHP' started by crazyryan, Mar 18, 2008.

  1. #1
    Hey, not quite sure on this but ...

    
    $url = '/joke/' . $row['joke_id'] . '-' . strtolower(str_replace('--', '-', str_replace(' ', '-', preg_replace('/[^\sA-Za-z0-9]+/', '', substr($row['joke_content'], 0, 60))))) . '.html';
    echo $url;
    
    PHP:
    Now, when the $url is echoed, it's showing this:
    /joke/152-why-were-ancient-egyptian-children- confused- because-t.html

    I don't see where them extra spaces are coming from...

    When $row['joke_content'] is echoed, this is shown:
    Why were ancient Egyptian children confused? Because their daddies were mummies.

    Perfect, but in the source this is shown:
    Why were ancient Egyptian children

    confused?
    Because their daddies were mummies.

    So, for some reason them extra lines are coming from no where, this seems to be the case with most jokes in the database, is there anything I can do to get rid of these new lines when echoing and also in the $url?

    Thanks
     
    crazyryan, Mar 18, 2008 IP
  2. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #2
    hi try this


    $text=preg_replace("/[rn]+[st]*[rn]+/","n",$row['joke_content']);

    $url = '/joke/' . $row['joke_id'] . '-' . strtolower(str_replace('--', '-', str_replace(' ', '-', preg_replace('/[^\sA-Za-z0-9]+/', '', substr($text, 0, 60))))) . '.html';echo $url;

    Regards

    Alex
     
    kmap, Mar 18, 2008 IP
  3. crazyryan

    crazyryan Well-Known Member

    Messages:
    3,087
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    175
    #3
    Hey Alex
    That didn't seem to change anything unfortunately.
     
    crazyryan, Mar 18, 2008 IP
  4. NoamBarz

    NoamBarz Active Member

    Messages:
    242
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #4
    Maybe something with the substr call - you may have the indices wrong
     
    NoamBarz, Mar 18, 2008 IP
  5. crazyryan

    crazyryan Well-Known Member

    Messages:
    3,087
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    175
    #5
    Pretty sure that substr is fine, since I'm not using it on the actual joke.
     
    crazyryan, Mar 18, 2008 IP