Jump to content

replace carriage return with a BR tag


rockon

Recommended Posts

Evening guys.

 

I've got a question that's bugging me.

 

My website allows visitors to submit lyrics that, when submitted by the user, goes straight to the database under "pending lyrics". I then go to an admin section of the script where I approve lyrics by pressing a button. They then go into the main database of lyrics. The problem is that even if they add BR tags or just use carriage return to make new lines, when they go in to the database the BR tags or carriage returns are ignored completely.

 

I've uploaded the submit-lyrics page where it's all on.

 

I was wondering if anyone knew how i could get around this?

 

My website is:

www.megalyrics.net

 

 

Hope to hear a reply!

 

Thanks guys,

 

Adam

 

[attachment deleted by admin]

Link to comment
Share on other sites

How would I know? It's your site  :P

 

You'll need to put it where ever you're getting information back from the database and want to display the line breaks correctly. If you post the source of a page that you need this to be done on we can show you specifically where in the code.

Link to comment
Share on other sites

nlbr2($varHoldingLyrics)

 

i think, not used this method or even new of this function till now, i have been using str_replace() to do this job up to now :D

Essentially, yes. But I think he's asking more specifically exactly where in the code; I'm guessing he's not familiar with it.

Link to comment
Share on other sites

I attached the file that has all the php in it but here is a source snippet of a page where the lyrics are. BR tags were added when submitting using a form but they disappear when submitted and put in the database.

 

 

<table width="100%" cellspacing="5" cellpadding="0"> 
  <tr> 
    <td valign="top"> 
	<table width='100%' cellspacing='0' cellpadding='0'><form method='POST' action='index.html'><input name='item' type='hidden' value='3'><tr><td colspan='2'><b>Viewing Lyrics for test:</b><br><br></td><td></td></tr><tr><td width='90'><font class='listingtitle'>Artist:</font></td><td>Test</td><td rowspan='9' valign='top'> 
	  
	  <table width='100%' cellspacing='0' cellpadding='0' style='padding-right:10px;'> 
		<tr><td align='center'></td></tr></table> 
	  
	  </td></tr><tr><td width='90'><font class='listingtitle'>Album:</font></td><td>test</td></tr><tr><td width='90'><font class='listingtitle'>Track:</font></td><td>test</td></tr><tr><td style='padding-top:4px;'></td><td> </td></tr><tr><td style='padding-top:4px;'><font class='listingtitle'>Date Added:</font></td><td style='padding-top:4px;'>28/09/2009</td></tr><tr><td style='padding-top:4px;'></td><td> </td></tr><tr><td valign='top' style='padding-top:4px;'><font class='listingtitle'>Lyrics:</font></td><td valign='top' style='padding-top:4px;'>test lyrics

second line

third line
fourth line</td></tr><tr><td style='padding-top:4px;'></td><td> </td></tr><tr><td style='padding-top:8px;'></td><td style='padding-top:8px;'> 
	  <img src='../themes/1/images/delicious.png' width='16' height='16' border='0'> <a href='http://del.icio.us/post?url=http%3A%2F%2Fwww.megalyrics.net%2Fview-3-test_test.html&title=test+by+Test+lyrics' target='_blank'>Add to del.icio.us</a>  
	  <img src='../themes/1/images/digg.png' width='16' height='16' border='0'> <a href='http://digg.com/submit?phase=2&url=http%3A%2F%2Fwww.megalyrics.net%2Fview-3-test_test.html&title=test+by+Test+lyrics' target='_blank'>Digg this</a>  
	  <img src='../themes/1/images/reddit.png' width='16' height='16' border='0'> <a href='http://reddit.com/submit?url=http%3A%2F%2Fwww.megalyrics.net%2Fview-3-test_test.html&title=test+by+Test+lyrics' target='_blank'>Reddit</a> 
	  </td></tr><tr><td valign='top' style='padding-top:24px;'></td><td valign='top' style='padding-top:24px;'><input name='approve' value='approve' type='submit'> <input name='decline' value='decline' type='submit'></td></tr></form></table>		</td> 
  </tr> 
</table> 

 

Link to comment
Share on other sites

when I go to phpmyadmin and view the submitted lyric in the db the br tags are gone. So it's removing them when the user presses submit and they go to the db.

 

When i edit the entry and add br tags it works. this would be inconvenient if i get a lot of submissions.

 

here is the source of the viewitem page that the lyrics are on

 

<?php

include_once("config.inc.php");
include_once("db_connect.php");

// get vars
$j    = $_REQUEST['j'];
$r    = $_REQUEST['r'];

if(!$j) {

$ptitle    = "ERROR";
$meta_keys = "search, lyrics, tunes, singing, words, toons, viewing";
$meta_desc = "ERROR";
$selected  = "VIEW";

include("header.php");

echo "<b>ERROR!</b><br><br>No lyrics were requested, please go back to the homepage and start again.<br>";

}
else {

$vote = $_REQUEST['vote'];
if($vote) {
  $lookup_field = "votestar".$vote;
  $get_values   = mysql_query("SELECT votestar1, votestar2, votestar3, votestar4, votestar5 FROM tracks WHERE id = ".$j." LIMIT 1");
  $votestar1 = mysql_result($get_values, 0, votestar1);
  $votestar2 = mysql_result($get_values, 0, votestar2);
  $votestar3 = mysql_result($get_values, 0, votestar3);
  $votestar4 = mysql_result($get_values, 0, votestar4);
  $votestar5 = mysql_result($get_values, 0, votestar5);
  if($vote == 1) $votestar1 = $votestar1+1;
  elseif($vote == 2) $votestar2 = $votestar2+1;
  elseif($vote == 3) $votestar3 = $votestar3+1;
  elseif($vote == 4) $votestar4 = $votestar4+1;
  elseif($vote == 5) $votestar5 = $votestar5+1;
  $total = ($votestar1 * 1)+($votestar2 * 2)+($votestar3 * 3)+($votestar4 * 4)+($votestar5 * 5);
  $total = $total/($votestar1+$votestar2+$votestar3+$votestar4+$votestar5);
  $update_joke = mysql_query("UPDATE tracks SET ".$lookup_field." = ".$$lookup_field.", votestartotal = ".$total." WHERE id = ".$j." LIMIT 1");
}

$lyricsqry = mysql_query("SELECT artist, album, title, dateadded, artwork, views, votestartotal FROM tracks WHERE id = ".$j." LIMIT 1");
if($lyricsqry) {
  $artist        = mysql_result($lyricsqry, 0, artist);
  $album         = mysql_result($lyricsqry, 0, album);
  if(strlen($album) == 0) $album = "Unknown";
  $title         = mysql_result($lyricsqry, 0, title);
  $dateadded     = mysql_result($lyricsqry, 0, dateadded);
  $dateadded     = substr($dateadded, 8, 2)."/".substr($dateadded, 5, 2)."/".substr($dateadded, 0, 4);
  $artwork       = mysql_result($lyricsqry, 0, artwork);
  $views         = mysql_result($lyricsqry, 0, views);
  $votestartotal = mysql_result($lyricsqry, 0, votestartotal);

  $lyricsqry2 = mysql_query("SELECT lyrics FROM lyrics WHERE trackid = ".$j." LIMIT 1");
  $lyrics        = wordwrap(stripslashes(mysql_result($lyricsqry2, 0, lyrics)), 100, "<br />\n", true);

  $newviews = $views+1;
  $update = mysql_query("UPDATE tracks SET views = ".$newviews." WHERE id = ".$j." LIMIT 1");
}
else die("ERROR LOOKING UP LYRICS");

$ptitle    = $title." lyrics";
$meta_keys = str_replace(" ", ", ", $title).", search, lyrics, music, tunes, mp3s, sing, karaoke";
$meta_desc = $title." lyrics";
if($r == 1) $selected = "RANDOM";
else $selected  = "VIEW";

include("header.php");

?>

<table width="100%" cellspacing="5" cellpadding="0">
  <tr>
    <td valign="top">
	<?php
	  echo "<table width='100%' cellspacing='0' cellpadding='0'>";
	  echo "<tr><td colspan='2' class='headertitle'><b>";
	  if($r == 1) echo "Random";
	  else echo "Viewing";
	  echo " Lyrics for ".$title.":</b><br><br></td><td></td></tr>";
	  echo "<tr><td width='90' ><font class='listingtitle'>Artist:</font></td><td>".$artist."</td><td rowspan='9' valign='top'>

	  <table width='100%' cellspacing='0' cellpadding='0' style='padding-right:10px;'>
		<tr><td align='center'>";

		echo show_artwork($j, 150);

		echo "</td></tr>";
		if(strlen($amazonid) > 0) {
		  $amazonurl = construct_amazon_url($artist, $album);
		  echo "<tr><td align='center' class='buylink'><a href='".$amazonurl."' target='_blank' class='buylink'>buy from<br><br class='smallBr'><br class='smallBr'><img src='themes/".$theme."/images/icon-amazon.jpg' border='0'></a></td></tr>";
		}
	  echo "</table>

	  </td></tr>";
	  echo "<tr><td width='90'><font class='listingtitle'>Album:</font></td><td>".$album."</td></tr>";
	  echo "<tr><td width='90'><font class='listingtitle'>Track:</font></td><td>".$title."</td></tr>";

	  echo "<tr><td style='padding-top:4px;'></td><td> </td></tr>";
	  echo "<tr><td style='padding-top:4px;'><font class='listingtitle'>Date Added:</font></td><td style='padding-top:4px;'>".$dateadded."</td></tr>";
	  if(number_format($votestartotal, 0) == 0) $rating = "not yet rated";
	  else $rating = number_format($votestartotal, 0)." stars";
	  echo "<form method='POST' action='view-".$j."-".trim(substr(urlconvert($joke), 0, 50)).".html'><tr><td style='padding-top:4px;'><font class='listingtitle'>Rating:</font></td><td style='padding-top:4px;'><img src='themes/".$theme."/images/small-stars-".number_format($votestartotal, 0).".gif' width='52' height='8' alt='".$rating."'>";
	  if(!$vote) echo "   <select name='vote' class='smallform'>
	    <option value=''>< rate ></option>
		<option value='1'>1 out of 5</option>
		<option value='2'>2 out of 5</option>
		<option value='3'>3 out of 5</option>
		<option value='4'>4 out of 5</option>
		<option value='5'>5 out of 5</option>
	  </select>  <input name='submit' type='submit' value='rate now' class='smallform'>";
	  echo "</td></tr></form>";
	  echo "<tr><td style='padding-top:4px;'><font class='listingtitle'>Views:</font></td><td style='padding-top:4px;'>".$newviews."</td></tr>";

	  echo "<tr><td style='padding-top:4px;'></td><td> </td></tr>";
	  echo "<tr><td valign='top' style='padding-top:4px;'><font class='listingtitle'>Lyrics:</font></td><td valign='top' style='padding-top:4px;'>".$lyrics."</td></tr>";

	  echo "<tr><td style='padding-top:4px;'></td><td> </td></tr>";
	  $this_url   = $site_path."view-".$j."-".urlconvert($artist)."_".urlconvert($title).".html";
	  $this_title = $title." by ".$artist." lyrics";
	  echo "<tr><td style='padding-top:8px;'></td><td style='padding-top:8px;'>
	  <img src='themes/".$theme."/images/delicious.png' width='16' height='16' border='0'> <a href='http://del.icio.us/post?url=".urlencode($this_url)."&title=".urlencode($this_title)."' target='_blank'>Add to del.icio.us</a>  
	  <img src='themes/".$theme."/images/digg.png' width='16' height='16' border='0'> <a href='http://digg.com/submit?phase=2&url=".urlencode($this_url)."&title=".urlencode($this_title)."' target='_blank'>Digg this</a>  
	  <img src='themes/".$theme."/images/reddit.png' width='16' height='16' border='0'> <a href='http://reddit.com/submit?url=".urlencode($this_url)."&title=".urlencode($this_title)."' target='_blank'>Reddit</a>
	  </td></tr>";

	  echo "</table>";

	?>

	</td>
  </tr>
  <tr><td colspan='2'><br><br><b>More <?php echo UCWords($artist); ?> Lyrics:</b><br><br></td></tr>
</table>

<?php

  $temp = mysql_query("SELECT id, title, artist FROM tracks WHERE artist = '$artist' ORDER BY RAND() LIMIT 10");
  echo "<table width='95%' cellspacing='3' cellpadding='0' align='center'>";
  $tracker = 1;
  while($row = mysql_fetch_array($temp)) {
    echo "<tr><td width='40' align='right'><b>".$tracker.".</b>   </td><td class='listingtitle'>".$row[title]."  <a href='view-".$row[id]."-".urlconvert($row[artist])."_".urlconvert($row[title]).".html' class='morelink'>view</a></td></tr>";
	$tracker++;
  }
  echo "</table><br>";
?>

<?php
}
?>

<?php
include("footer.php");
?>

 

Link to comment
Share on other sites

Try changing:

 

$lyrics        = wordwrap(stripslashes(mysql_result($lyricsqry2, 0, lyrics)), 100, "<br />\n", true);

to

$lyrics        = wordwrap(stripslashes(nlb2(mysql_result($lyricsqry2, 0, lyrics))), 100, "<br />\n", true);

Link to comment
Share on other sites

It still removes the BR tag as soon as the lyrics are submitted using the form. I know this because it goes into a section of the db called pending - when viewing the submitted lyrics there is no mark up at all. it shows carriage returns though.

 

Maybe if there was a 'replace carriage return with <br /> when getting the lyrics from db' ? or something to that effect?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.