nightkarnation Posted January 8, 2009 Share Posted January 8, 2009 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, Quote Link to comment https://forums.phpfreaks.com/topic/139937-php-reading-text-from-mysql-but-inventing-enter-spaces-through-text/ Share on other sites More sharing options...
Maq Posted January 8, 2009 Share Posted January 8, 2009 code please Quote Link to comment https://forums.phpfreaks.com/topic/139937-php-reading-text-from-mysql-but-inventing-enter-spaces-through-text/#findComment-732139 Share on other sites More sharing options...
nightkarnation Posted January 8, 2009 Author Share Posted January 8, 2009 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; Quote Link to comment https://forums.phpfreaks.com/topic/139937-php-reading-text-from-mysql-but-inventing-enter-spaces-through-text/#findComment-732142 Share on other sites More sharing options...
Maq Posted January 8, 2009 Share Posted January 8, 2009 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'] . "&"; Quote Link to comment https://forums.phpfreaks.com/topic/139937-php-reading-text-from-mysql-but-inventing-enter-spaces-through-text/#findComment-732149 Share on other sites More sharing options...
nightkarnation Posted January 8, 2009 Author Share Posted January 8, 2009 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, Quote Link to comment https://forums.phpfreaks.com/topic/139937-php-reading-text-from-mysql-but-inventing-enter-spaces-through-text/#findComment-732683 Share on other sites More sharing options...
premiso Posted January 8, 2009 Share Posted January 8, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/139937-php-reading-text-from-mysql-but-inventing-enter-spaces-through-text/#findComment-732686 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.