Jump to content

Php reading text from Mysql but inventing enter spaces through text


nightkarnation

Recommended Posts

Hello! Im working on a project and in this particular event im having a problem...

 

Lets say i have a text (stored as mediumtext) successfully saved on mysql:

 

Hello
How are you?
Im fine

 

Ok...

Now im retreveing that text with php and its being displayed like this:

 

Hello

How are you?

Im fine

 

Why is it creating enter spaces?

What am i doing wrong? or what should i change?

 

Thanx in advance!

Cheers,

PHP

//retrieve the lyrics from the selected song
if ($action == "loadLyrics")
{
$title=$_POST['txtTitle'];

        $result = mysql_query("SELECT title, link, lyrics FROM videla_songs WHERE title = '$title'"); 
        $cant = 0; 
        while($row=mysql_fetch_array($result)){ 
            echo "title$cant=$row[title]&link$cant=$row[link]&lyrics$cant=$row[lyrics]&"; 
            $cant++; 
        } 
        echo "cant=$cant"; 
}

 

RELEVANT FLASH CODE:

txtSongLyrics.text = content_lv.lyrics0;

Try this, your code looks weird (and you don't need that extra ampersand at the end).

 

echo "title" . $cant . "=" . $row['title'] . "&link" . $cant . "=" . $row['link'] . "&lyrics" . " . $cant . "=" . $row['lyrics'] . "&";

Thanx for your reply!

Correct code:

echo "title" . $cant . "=" . $row['title'] . "&link" . $cant . "=" . $row['link'] . "&lyrics" . $cant . "=" . $row['lyrics'] . "&";

 

Is doing the same...the enter spaces are still being performed...

 

Any other ideas, anyone?

 

Thanx for the help!

Cheers,

If the spaces are at the beginning or end of the deal you can use trim on each variable to trim them out.

 

If they are mixed in and I take "enter spaces" as a new line you can try using str_replace

 

<?php
$test = "This is a test\n of the emergency\r\n brodcast system";
$replace = array("\n", "\r\n");
$test = str_replace($replace, "", $test);
?>

 

Either way that should help you out a bit.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.