refiking Posted November 22, 2008 Share Posted November 22, 2008 I have records in a db like this line1<br> line2<br> What I need are 2 different variables. Here's the code I have (or more of what I need) while ($row = mysql_fetch_assoc($sql){ $line1 = //everything before the <br> tag $line2 = //everything between the two <br> tags Quote Link to comment https://forums.phpfreaks.com/topic/133760-solved-finding-a-string-within-a-string-2-different-locations/ Share on other sites More sharing options...
JasonLewis Posted November 22, 2008 Share Posted November 22, 2008 Well, that code is incorrect because your missing a bracket off your while() loop. So, basically you have 2 lines in your database, in the one field. And you stored at <br> tag in there as well? Or is it a newline? Hm, please explain a bit more. Here is what I'm thinking though. while($row = mysql_fetch_assoc($sql)){ $lines = explode("<br>", $row['field']); $line1 = $lines[0]; //Should hold line1 $line2 = $lines[1]; //Should hold line2 } Quote Link to comment https://forums.phpfreaks.com/topic/133760-solved-finding-a-string-within-a-string-2-different-locations/#findComment-696087 Share on other sites More sharing options...
refiking Posted November 22, 2008 Author Share Posted November 22, 2008 Almost. Line2 still has a <br> tag there. How can I remove that one as well? Quote Link to comment https://forums.phpfreaks.com/topic/133760-solved-finding-a-string-within-a-string-2-different-locations/#findComment-696092 Share on other sites More sharing options...
JasonLewis Posted November 22, 2008 Share Posted November 22, 2008 It does? It shouldn't. Quote Link to comment https://forums.phpfreaks.com/topic/133760-solved-finding-a-string-within-a-string-2-different-locations/#findComment-696094 Share on other sites More sharing options...
refiking Posted November 22, 2008 Author Share Posted November 22, 2008 Sorry. It did. I forgot to add the tag to one of the records and it screwed up the table. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/133760-solved-finding-a-string-within-a-string-2-different-locations/#findComment-696100 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.