Texan78 Posted May 13, 2014 Share Posted May 13, 2014 Hello, I have this XML file I am parsing and I have hit a small formatting issue that I can't seem to get around. Here is what the the output of the RSS looks like. <description><![CDATA[<div style='text-align:left;'>Exit ramp closed. <br/><b>Current Status:</b> Open<br/><b>Affected Lanes:</b> Exit Ramp<br/><b>Dates:</b> Wednesday, May 28 - Thursday, May 29<br/><b>Days Closed:</b> <font color='#808080'>S</font><font color='#808080'>M</font><font color='#808080'>T</font><font color='#FF0000'><b>W</b></font><font color='#FF0000'><b>T</b></font><font color='#808080'>F</font><font color='#808080'>S</font> 20:00 PM - 6:00 AM</div>]]></description> Notice at the first is "Exit ramp closed." There is nothing before it but, for some weird reason when I parse it. It is on a new line like so, notice it should be up there with "Incident" but, it is dropped down below it. Incident: Exit ramp closed. Current Status: Open Affected Lanes: Exit Ramp Dates: Wednesday, May 28 - Thursday, May 29 Days Closed: SMTWTFS 20:00 PM - 6:00 AM This is how it is formated in the td cell. <td style='{$td2Style}'><strong>Incident:</strong> {$incident_data_desc}</td>\n"; So as you can see above, there is nothing before it that would cause it to break to a new line both in the table or in the RSS. So how can I remove that first return only is that is on the same line with it and not below it. I have tried this and a couple of other things like trim with no luck. $description = $item->description; $incident_data_desc = str_replace("\r", '', $description ); Note, I only need that first one removed, the others are fine. I can do it but it will remove all the breaks and I only want to remove that first one that is causing the line to be on a new line. Any suggestions? -Thanks Quote Link to comment https://forums.phpfreaks.com/topic/288455-removing-only-the-first-line-break-at-the-beginning-of-string/ Share on other sites More sharing options...
Jacques1 Posted May 13, 2014 Share Posted May 13, 2014 Well, this is how HTML works. Block elements like div are displayed on a new line. If you don't want the div element, remove the tags. Quote Link to comment https://forums.phpfreaks.com/topic/288455-removing-only-the-first-line-break-at-the-beginning-of-string/#findComment-1479316 Share on other sites More sharing options...
Barand Posted May 13, 2014 Share Posted May 13, 2014 You could float the div element to the right <html> <head> <title>test</title> <style type='text/css'> div { float: right; } </style> </head> <body> <?php echo $tData;?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/288455-removing-only-the-first-line-break-at-the-beginning-of-string/#findComment-1479318 Share on other sites More sharing options...
Texan78 Posted May 13, 2014 Author Share Posted May 13, 2014 Thanks but, this is not my feed so I have no control over how it is styled. It comes as is so I can't alter it With that said. Could I use something to remove it? Not sure what I could use that would just remove the div. Quote Link to comment https://forums.phpfreaks.com/topic/288455-removing-only-the-first-line-break-at-the-beginning-of-string/#findComment-1479323 Share on other sites More sharing options...
Ch0cu3r Posted May 13, 2014 Share Posted May 13, 2014 (edited) It is caused by the div as Jacques1 pointed out. So to prevent the break between the Incident and Exit Ramp text you need to remove the <div></div> tags. Example // strip the div tags from the data $incident_data_desc = preg_replace('~^<div[^>]+>(.*?)</div>$~is', '$1', $incident_data_desc); Edited May 13, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/288455-removing-only-the-first-line-break-at-the-beginning-of-string/#findComment-1479328 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.