Explode command

Discussion in 'PHP' started by kirpy, Dec 10, 2005.

  1. #1
    I am having problem with it. I have one echo for my news row that lists the news. I want to end the lines after dots and question marks (both) and i couldn't find a way.. Using substr instead is not a good idea.

    *is puzzled* :confused:
     
    kirpy, Dec 10, 2005 IP
  2. timothyleary

    timothyleary Peon

    Messages:
    46
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    let's have a look at the code, maybe it's just somthing you overlooked
     
    timothyleary, Dec 10, 2005 IP
  3. kirpy

    kirpy Member

    Messages:
    61
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    48
    #3
    I use

    
    $i= explode(".", $row['news']);
    
    Code (markup):
    then
    
    echo $i[0];
    
    Code (markup):
    when i use two explode commands i get two echos.
     
    kirpy, Dec 11, 2005 IP
  4. piniyini

    piniyini Well-Known Member

    Messages:
    514
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    170
    #4
    what is $row['news'] likely to be? give us an example please
     
    piniyini, Dec 11, 2005 IP
  5. kirpy

    kirpy Member

    Messages:
    61
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    48
    #5
    It gets the news from db and prints it there. I am trying to make kinda read more... thing. So i want to end the lines from dots or question marks.
     
    kirpy, Dec 11, 2005 IP
  6. rvarcher

    rvarcher Peon

    Messages:
    69
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Haven't tested this code but here's my suggestion.

    
    $news = str_replace ( ".", ".<br><br>", $news );
    
    $news = str_replace ( "?", "?<br><br>", $news );
    
    echo $news;
    
    PHP:
     
    rvarcher, Dec 12, 2005 IP
  7. kirpy

    kirpy Member

    Messages:
    61
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    48
    #7
    It echoes nothing now rvarcher
    @piniyini what matters the news content? say first news is like blah blah, blah blah? blah blah. and second is like blah blah blah blah. blah blah blah.

    
    $news = str_replace ( ".", ".<br>", $news );
    $news = str_replace ( "?", "?<br>", $news );
    echo $news;
    
    Code (markup):
    All my news start with code <p> may be that?
     
    kirpy, Dec 13, 2005 IP
  8. kirpy

    kirpy Member

    Messages:
    61
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    48
    #8
    @rvarcher i got the problem that was becase i didn't call it from db. But what i want to do is get just some part of the news. Then when it is clicked it goes to the full news. The way you write prints all the news under them :eek:
     
    kirpy, Dec 13, 2005 IP
  9. rvarcher

    rvarcher Peon

    Messages:
    69
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I'm not sure what you're trying to do. Are you taking a set of news stories and outputting the first sentence of each story to create something like an index list? (Like something I would see on http://news.yahoo.com)
     
    rvarcher, Dec 13, 2005 IP
  10. kirpy

    kirpy Member

    Messages:
    61
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    48
    #10
    Yeah just like that i am trying to get the first sentences of the news and print them on the page.
     
    kirpy, Dec 13, 2005 IP