1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

very basic php question

Discussion in 'PHP' started by baris22, Dec 6, 2007.

  1. #1
    Hello all,

    my php is not good. I have got wordwrap here. it works perfect.

    
    $text=$row['description'];
    $newtext = wordwrap($text, 100, "\n", true);
    echo "$newtext\n";
    
    PHP:
    I want to use $newtext\n instead of $row['description'] in here aswell.

    
    <td align="left"><?=substr($row['description'],0,500); ?></td>
    
    PHP:
    I do not know how to do. can anyone help me?

    Thanks
     
    baris22, Dec 6, 2007 IP
  2. Gawk

    Gawk Peon

    Messages:
    427
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <td align="left"><?=substr($newtext,0,500); ?></td>
    PHP:
     
    Gawk, Dec 6, 2007 IP
  3. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #3
    It does not work.

    Thanks
     
    baris22, Dec 7, 2007 IP
  4. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #4
    Your syntax looks screwed, try this
    
    <td align="left"><?php echo substr($newtext, 0, 500); ?></td>
    
    Code (php):
     
    Kaizoku, Dec 7, 2007 IP
  5. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #5
    it does not work either.

    Thanks
     
    baris22, Dec 7, 2007 IP
  6. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #6
    Do you even know what substr does? and how to apply the $newtext?
     
    Kaizoku, Dec 7, 2007 IP
  7. Gawk

    Gawk Peon

    Messages:
    427
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I think he expects it to wrap in html, of course he needs to put <br>'s in instead of \n's

    <td align="left"><?php echo ereg_replace("\n","<br>",substr($newtext, 0, 500)); ?></td>
    PHP:
    or

    <td align="left"><?php echo nl2br(substr($newtext, 0, 500)); ?></td>
    PHP:
     
    Gawk, Dec 7, 2007 IP
  8. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #8
    I have got 2 pages.

    1-listing
    2-description

    At the moment i am using this on description page
    
    $text=$row['description'];$newtext = wordwrap($text, 100, "\n", true);echo "$newtext\n";
    
    PHP:
    it puts space if the word is longer than 100 character. It works perfect.


    I am using this for listing page
    
    <td align="left"><?=substr($row['description'],0,500); ?></td>
    
    PHP:
    I am limiting the content to 500 character. It works perfect.

    But i get problem if there is words like dddddddddddddddddddddddddddd

    to stop that i want to use

    
    <td align="left"><?php echo substr($newtext, 0, 500); ?></td>
    
    PHP:
    but does not work.
     
    baris22, Dec 7, 2007 IP