markhfla Posted April 25, 2008 Share Posted April 25, 2008 I'm trying to send text from a mysql database to a flash file through a string variable. But, the string shows up in my code with line breaks from when it was entered into the database from a form. In order for the flash file to read the string, it must all be on one line in the code. How can I remove these line breaks using PHP? I don't really want to remove them from the actual database text. Here's what I'm getting: description_text.swf?description=This is the way it's showing up with the <br> tag and on separate line. This doesn't work. Here's what I want: description_text.swf?description=This is the way I want it to show up with the<br>tag and all on one line. This does work! Link to comment https://forums.phpfreaks.com/topic/102824-removing-line-breaks-in-string-variable/ Share on other sites More sharing options...
DarkWater Posted April 25, 2008 Share Posted April 25, 2008 str_replace("\n", "", $row['text']); Fill in the correct row. =P Link to comment https://forums.phpfreaks.com/topic/102824-removing-line-breaks-in-string-variable/#findComment-526701 Share on other sites More sharing options...
markhfla Posted April 25, 2008 Author Share Posted April 25, 2008 WOW! That's the fastest response I've ever gotten. Thanks. Unfortuantely, I've tried that and it doesn't work. If this helps, here's some of the code: $desc = str_replace("'","'",$myrow["full_description"]); $desc = str_replace('"',""",$desc); $desc=str_replace("<p>","<br><br>",$desc); $desc=str_replace("\n","",$desc); Link to comment https://forums.phpfreaks.com/topic/102824-removing-line-breaks-in-string-variable/#findComment-526705 Share on other sites More sharing options...
DarkWater Posted April 25, 2008 Share Posted April 25, 2008 $breaks = array("\r\n", "\n", "\r"); $newtext = str_replace($breaks, "", $text); Try that. >_> Link to comment https://forums.phpfreaks.com/topic/102824-removing-line-breaks-in-string-variable/#findComment-526707 Share on other sites More sharing options...
Fadion Posted April 25, 2008 Share Posted April 25, 2008 $desc=str_replace("<p>","<br><br>",$desc); Shouldnt also be a: $desc = str_replace('</p>', '', $desc); or u usually dont close tags Link to comment https://forums.phpfreaks.com/topic/102824-removing-line-breaks-in-string-variable/#findComment-526735 Share on other sites More sharing options...
markhfla Posted April 25, 2008 Author Share Posted April 25, 2008 DarkWater, A thousand blessings on your household! That worked. WHEW! GuiltyGear, I built the admin for this site years ago. So, my client just enters an open p tag. One of these days I'm going to have to get around to adding an html editor. Although, with the current problem I just had, maybe that's not such a good idea! :-P Link to comment https://forums.phpfreaks.com/topic/102824-removing-line-breaks-in-string-variable/#findComment-526752 Share on other sites More sharing options...
DarkWater Posted April 25, 2008 Share Posted April 25, 2008 Any time, dude. =) Glad I could help. I hate how sometimes it's \r or \n or \r\n. D: Depends on the OS and stuff. So yeah, glad I could get that sorted out for you. Happy coding. =P Link to comment https://forums.phpfreaks.com/topic/102824-removing-line-breaks-in-string-variable/#findComment-526753 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.