robcrozier Posted November 24, 2006 Share Posted November 24, 2006 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!!! Quote Link to comment https://forums.phpfreaks.com/topic/28371-devide-up-string-from-mysql/ Share on other sites More sharing options...
printf Posted November 24, 2006 Share Posted November 24, 2006 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 Xprintf Quote Link to comment https://forums.phpfreaks.com/topic/28371-devide-up-string-from-mysql/#findComment-129775 Share on other sites More sharing options...
robcrozier Posted November 24, 2006 Author Share Posted November 24, 2006 cheers mate thats done the trick! Quote Link to comment https://forums.phpfreaks.com/topic/28371-devide-up-string-from-mysql/#findComment-129778 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.