I have proplem with PHP scrpit

Discussion in 'PHP' started by No-Name-, Dec 11, 2008.

  1. #1
    Hi,
    I have PHP script and I want to use the script to write stories but the problem is the story (article) will show in description.
    I want the description(in source ) be the first 20 words from description:D
    For example, like any forum the thread maybe 1000 words but the description just 20 words

    sorry about my English but I am doing my best :(
     
    No-Name-, Dec 11, 2008 IP
  2. elias_sorensen

    elias_sorensen Well-Known Member

    Messages:
    852
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #2
    Do it like this:

    
    $count= 20; //How many words you want to display
    $output = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla scelerisque. Nullam posuere sapien. Aenean nec pede quis justo tempus ultrices. Praesent ac purus in quam rhoncus vehicula. Donec varius massa vel nulla. Donec dictum, odio ac volutpat fringilla, nisl ligula lobortis eros, ac congue tortor mauris sit amet quam.'; //Your text
    $words = explode(' ', $output); //Split every word into an array
    $words = array_slice($words, 0, $count); //Split the array, so that we only got 20 words.
    $output= implode(' ', $words); //Join the arrays again to one string.
    echo $output;
    
    PHP:
     
    elias_sorensen, Dec 11, 2008 IP
  3. No-Name-

    No-Name- Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thank you very much,But excuse me
    Can you tell me more because I do not know a lot about PHP

    in the attachment the file that I need to change it can you tell me where I can put php code
     

    Attached Files:

    No-Name-, Dec 11, 2008 IP
  4. Nightcoder

    Nightcoder Active Member

    Messages:
    521
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #4
    This should do the trick...

    <? echo "".substr($rfileDescription,0,20).""; ?>
    PHP:
    Hope it helps...
     
    Nightcoder, Dec 11, 2008 IP
  5. elias_sorensen

    elias_sorensen Well-Known Member

    Messages:
    852
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #5
    Nightcoder, that does only show the first 20 characters. Not the first 20 words. :)

    And your echo looks kind of weird. You should just do this:
    <? echo substr($rfileDescription,0,20); ?>
    PHP:
    , no needs for using quotes lol :)

    But.. Still use my method:
    
    $count= 20; //How many words you want to display
    $output = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla scelerisque. Nullam posuere sapien. Aenean nec pede quis justo tempus ultrices. Praesent ac purus in quam rhoncus vehicula. Donec varius massa vel nulla. Donec dictum, odio ac volutpat fringilla, nisl ligula lobortis eros, ac congue tortor mauris sit amet quam.'; //Your text
    $words = explode(' ', $output); //Split every word into an array
    $words = array_slice($words, 0, $count); //Split the array, so that we only got 20 words.
    $output= implode(' ', $words); //Join the arrays again to one string.
    echo $output;
    
    PHP:
     
    elias_sorensen, Dec 11, 2008 IP
  6. No-Name-

    No-Name- Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Nightcoder,elias_sorensen thank you very much but where I can put this code :confused::confused:because I do not know PHP:(
     
    No-Name-, Dec 12, 2008 IP
  7. elias_sorensen

    elias_sorensen Well-Known Member

    Messages:
    852
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #7
    You put the code where you want the 20 words to be displayed :) Use mine, if you use nightcoder's, you'll only get 20 characters.
     
    elias_sorensen, Dec 12, 2008 IP
  8. No-Name-

    No-Name- Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    thanks for helping meelias_sorensen but :( I want the 20 words displayed in this file can you do it for me ? :( because I tried many times
    http://forums.digitalpoint.com/attachment.php?attachmentid=22450&d=1229002495
     
    No-Name-, Dec 12, 2008 IP
  9. matthewrobertbell

    matthewrobertbell Peon

    Messages:
    781
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Perfect oppurtunity to learn php, so you can help yourself next time ;)
     
    matthewrobertbell, Dec 13, 2008 IP