www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 22

Thread: Adding <br>

  1. #1
    Join Date
    Jan 2003
    Location
    Windsor, UK
    Posts
    367

    Adding <br>

    I have a a script that write a form input to .sng file (which
    using htaccess that I have setup on the server is excatly the
    same as a php file) Also when putting a word like don't in it adds a slash in front of the apostrophe.

    So hence if you save the data as:

    Line 1 text you're here
    Line 2 text here


    When the browser reads it it doesn't see a <br> command and so prints the above as:

    Line 1 text you\'re hereLine 2 text here
    (note this forum must be using the technology I need as it won't display the slash i purposely put in front of the ' above and it inserts line breaks in the correct place.

    My two question are: How do you get the script to insert <br> tags where they are needed, and make sure it doesn't save the slashs at the same time.

    If someone could put it in the script I have below I would be most greatful!

    Cheers all!

    PHP Code:
    <?
    include ("config.php");

    echo (
    $Style);

    if(
    $song == "" || $lyrics == "")
     {
      
    $HTML = ($sHeaderHTML);
      
    $HTML .= ("<form method=\"post\" action=\"add.php\">");
      
    $HTML .= ($sBeforeHTML "Song name:" $sAfterHTML $sBeforeHTML "<input name=\"song\"><br>" $sAfterHTML $sSplitHTML);
      
    $HTML .= ($sBeforeHTML "Midi URL:" $sAfterHTML $sBeforeHTML "<input name=\"midiurl\"><br>" $sAfterHTML $sSplitHTML);
      
    $HTML .= ($sBeforeHTML "Lyrics:" $sAfterHTML $sBeforeHTML "<textarea name=\"lyrics\" rows=\"10\" cols=\"40\"></textarea><br>" $sAfterHTML $sSplitHTML);
      
    $HTML .= ($sBeforeHTML "<input type=\"submit\" value=\"Submit\">" $sAfterHTML);
      
    $HTML .= ($sBeforeHTML "<input type=\"reset\" value=\"Reset\">" $sAfterHTML);
      
    $HTML .= ($sFooterHTML);
      print (
    $HTML);
     }
      else
     {
      if(
    $autoadd == (false))
       {
        
    $filename = ("l-".$song.".dat");
       }
        else
       {
        
    $filename = ("l-".$song.".sng");
       }
      if(
    file_exists($filename))
       {
        echo (
    "The lyrics you submitted already exist");
       }
        else
       {
        
    $data .= $HNewTemp;
        
    $data .= "Song name: ".$song."<br>\n";
        
    $data .= "Midi URL: <a href='midi/".$midiurl."' onclick=\"NewWindow(this.href,'lmidi','200','100','no','center');return false\">Open Midi File</a><br>\n";
        
    $data .= "Lyrics: ".$lyrics."\n";
        
    $data .= $FNewTemp;
        
    $openfile fopen(("$filename"),"w");
        
    fwrite($openfile"$data");
        
    fclose($openfile);
        echo (
    "<script language=\"JavaScript\">window.location='add.php'</script>");
       }
     }
    ?>
    Last edited by GavinPearce; 11-16-2003 at 09:40 AM.

  2. #2
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104

  3. #3
    Join Date
    Jan 2003
    Location
    Windsor, UK
    Posts
    367
    Ok so I have

    PHP Code:
    <?
    function nl2br($str) {
    $str preg_replace('/\n/i''<br />'$str);
    }

    function 
    br2nl($str) {
    $str preg_replace('/<br( )?(\/)?>/i''\n'$str);
    }

    // And a fun little xhtml function to use
    function br2xhtml($str) {
    $str preg_replace('/<br( )?(\/)?>/i''<br />'$str);
    }
    ?>
    and

    PHP Code:
    echo stripslashes($str); 
    I don't suppose you could insert the two functions into my orginal script for me please pyro?

  4. #4
    Join Date
    Jan 2003
    Location
    Windsor, UK
    Posts
    367
    Also found..

    PHP Code:
    <?
    if (get_magic_quotes_gpc()."" == "1") {
    foreach(
    $_GET as $k=>$v$_GET["$k"]=stripslashes($v);
    foreach(
    $_POST as $k=>$v$_POST["$k"]=stripslashes($v);
    foreach(
    $_COOKIE as $k=>$v$_COOKIE["$k"]=stripslashes($v);
    }
    // Strips all extra quotes
    ?>
    ...if it's any use

    Cheers again

  5. #5
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Change:

    PHP Code:
    $openfile fopen(("$filename"),"w");
    fwrite($openfile"$data");
    fclose($openfile); 
    To:

    PHP Code:
    $contents file($filename);
    $lines "";
    foreach (
    $contents as $line) {
        
    $lines .= $line;
    }
    echo 
    nl2br(stripslashes($lines)); 

  6. #6
    Join Date
    Jan 2003
    Location
    Windsor, UK
    Posts
    367
    Doesn't work. Now it's not writing a file at all.

    PHP Code:
    <?
    include ("config.php");

    echo (
    $Style);

    if(
    $song == "" || $lyrics == "")
     {
      
    $HTML = ($sHeaderHTML);
      
    $HTML .= ("<form method=\"post\" action=\"add.php\">");
      
    $HTML .= ($sBeforeHTML "Song name:" $sAfterHTML $sBeforeHTML "<input name=\"song\"><br>" $sAfterHTML $sSplitHTML);
      
    $HTML .= ($sBeforeHTML "Midi URL:" $sAfterHTML $sBeforeHTML "<input name=\"midiurl\"><br>" $sAfterHTML $sSplitHTML);
      
    $HTML .= ($sBeforeHTML "Lyrics:" $sAfterHTML $sBeforeHTML "<textarea name=\"lyrics\" rows=\"10\" cols=\"40\"></textarea><br>" $sAfterHTML $sSplitHTML);
      
    $HTML .= ($sBeforeHTML "<input type=\"submit\" value=\"Submit\">" $sAfterHTML);
      
    $HTML .= ($sBeforeHTML "<input type=\"reset\" value=\"Reset\">" $sAfterHTML);
      
    $HTML .= ($sFooterHTML);
      print (
    $HTML);
     }
      else
     {
      if(
    $autoadd == (false))
       {
        
    $filename = ("l-".$song.".dat");
       }
        else
       {
        
    $filename = ("l-".$song.".sng");
       }
      if(
    file_exists($filename))
       {
        echo (
    "The lyrics you submitted already exist");
       }
        else
       {
        
    $data .= $HNewTemp;
        
    $data .= "Song name: ".$song."<br>\n";
        
    $data .= "Midi URL: <a href='midi/".$midiurl."' onclick=\"NewWindow(this.href,'lmidi','200','100','no','center');return false\">Open Midi File</a><br>\n";
        
    $data .= "Lyrics: ".$lyrics."\n";
        
    $data .= $FNewTemp;
        
    $contents file($filename);
        
    $lines "";
        foreach (
    $contents as $line) {
        
    $lines .= $line;
    }
    echo 
    nl2br(stripslashes($lines));
        echo (
    "<script language=\"JavaScript\">window.location='add.php'</script>");
       }
     }
    ?>

  7. #7
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Cripes, my bad. In your original script, what prints out the files contents?

  8. #8
    Join Date
    Jan 2003
    Location
    Windsor, UK
    Posts
    367
    PHP Code:
    $filename = ("l-".$song.".sng"); //sets the filename
       
    }
      if(
    file_exists($filename)) //if it is already there 
       
    {
        echo (
    "The lyrics you submitted already exist");
       }
        else
       {

     
    // All data to be writen into the file

        
    $data .= $HNewTemp
        
    $data .= "Song name: ".$song."<br>\n"
        
    $data .= "Midi URL: <a href='midi/".$midiurl."' onclick=\"NewWindow(this.href,'lmidi','200','100','no','center');return false\">Open Midi File</a><br>\n";
        
    $data .= "Lyrics: ".$lyrics."\n";
        
    $data .= $FNewTemp;
        
    $openfile fopen(("$filename"),"w"); //open file 
        
    fwrite($openfile"$data"); // write to file
        
    fclose($openfile); //close file thats open 
    The data is input by the top half of the main script (above is jsut hte bottom half) which is a form that will keep apearing unless the two required fields are filled in. When filled in it sets the filename and writes the contents of the form into certain sections. I.e there is a form input called lyrics, and it add that as data to the file using: $data .= "Lyrics: ".$lyrics."\n";

  9. #9
    Join Date
    Jan 2003
    Location
    Windsor, UK
    Posts
    367
    The script basically takes a form input and saves it with a few extra values stored in a config file to the same directory with an extension of .sng which using .htaccess I have set-up to be the same as a .php extension on the server.

  10. #10
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Unless I'm missing it, you still haven't shown what code you are using to display the contents of the file.

  11. #11
    Join Date
    Jan 2003
    Location
    Windsor, UK
    Posts
    367
    I'm not. I need the strip slashes bit done when it writes the file rather than when you call it back.

    The file is just being called in the browser like a normal .htm file.

  12. #12
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    PHP Code:
    $data stripslashes($data);
    fwrite ($openfile$data); 

  13. #13
    Join Date
    Jan 2003
    Location
    Windsor, UK
    Posts
    367
    how about the line break bit?

  14. #14
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    See if you can get it from this line, which I gave you earlier:
    Originally posted by pyro
    PHP Code:
    echo nl2br(stripslashes($lines)); 

  15. #15
    Join Date
    Jan 2003
    Location
    Windsor, UK
    Posts
    367
    mayb dis

    $data = nl2br(stripslashes($data));
    fwrite ($openfile, $data);


    ?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles