Jump to content

devide up string from mysql


robcrozier

Recommended Posts

hi, does anyone know how i can divide up a string fetched from a database field. Basically i have a string which contains individual values separated by <br> in the database field. I don't just want to print out the string with the <br> which will merely put the individual values on a new line. I would like to completely break up the string so i can have full control over each value. Here's an example of what the database field would look like:

value1<br>value2<br>value3<br> ...

I want to be able to break this up into individual values (i.e value1, value2, value3)

Thanks for your help!!!
Link to comment
https://forums.phpfreaks.com/topic/28371-devide-up-string-from-mysql/
Share on other sites

For something like this you are better off doing it in your result loop, you can do it in the database with some string functions, but it would be better done in your script, because you would need 6 db functions, two for each variable just to return each part.

[code]while ( $row = mysql_fetch_assoc ( $result ) )
{
list ( $value1, $value2, $value3 ) = explode ( "\r\n", $row['fiend_name_to_split'] );

echo $value3;
}[/code]

Where "\r\n", would be "\r\n" on Windows, "\n" on Unix/Linux, "\r" on Mac/OS X


printf

Archived

This topic is now archived and is closed to further replies.

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