SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Nov 2003
    Location
    Brisbane, Australia
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Remove and line spaces when pulling from the DB

    Hi All

    I have a really annoying problem, that is probably really easy to fix but I just can't get it.

    I have some JavaScript that is populated from the DB. The information needs to be in 1 line in the JavaScript for it to work.

    Correct:

    HTML Code:
    <td valign='top' width='133' onclick="MM_changeProp('style','','innerHTML','86083','DIV');MM_changeProp('center','','innerHTML','<p><font size=3><strong>86083</strong></font></p><P><STRONG>Colours:</STRONG> Bubblegum, Turquoise</P><P><STRONG>Sizes:</STRONG> 2 - 18 and plus sized 20 - 30<BR></P>','DIV');MM_changeProp('views','','style.visibility','visible','DIV');MM_changeProp('view1','','style.textDecoration','none','SPAN');MM_changeProp('view2','','style.textDecoration','underline','SPAN');MM_changeProp('hintimage','','alt','86083','IMG')">
    The above is all on one line and works fine.

    Incorrect:

    HTML Code:
    <td valign='top' width='133' onclick="MM_changeProp('style','','innerHTML','86083','DIV');MM_changeProp('center','','innerHTML','<p><font size=3><strong>86083</strong></font></p><P><STRONG>Colours:</STRONG> Bubblegum, Turquoise</P>
    <P><STRONG>Sizes:</STRONG> 2 - 18 and plus sized 20 - 30<BR></P>','DIV');MM_changeProp('views','','style.visibility','visible','DIV');MM_changeProp('view1','','style.textDecoration','none','SPAN');MM_changeProp('view2','','style.textDecoration','underline','SPAN');MM_changeProp('hintimage','','alt','86083','IMG')">
    The above will not would as there is a line break between 2 p tags.

    I have tried using the following to replace the line breaks when I pull it from the DB:

    PHP Code:
    $maintext ereg_replace(">
    <"
    ,"><",$row['text']);
                    
    $maintext2 ereg_replace("</P>
    <P>"
    ,"</P><P>",$maintext); 
    but it doesn't seem to work.

    Any idea how to remove the line breaks to force the code from the DB to stay on one line?

    Any help would be great.

    Many Thanks

    mrmbarnes

  2. #2
    SitePoint Addict
    Join Date
    Jul 2008
    Location
    sudo rm -rf /
    Posts
    386
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use str_replace("\n",'',$str) to remove line breaks.

  3. #3
    SitePoint Evangelist
    Join Date
    Nov 2003
    Location
    Brisbane, Australia
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    Thanks for that but it didn't work.

    Any other ideas?

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    json_encode()


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •