Jump to content

[SOLVED] Finding a string within a string - 2 different locations


Recommended Posts

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

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
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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