dreamwest Posted January 6, 2010 Share Posted January 6, 2010 Ive stored a string in the database with deliminators "|" now how can i seperate the string and add extra info to it String: Sam Neill|William H. Macy|Tea Leoni| What i need: <a href='/Movies/&actor=Sam Neill'>Sam Neill</a> <a href='/Movies/&actor=William H. Macy'>William H. Macy</a> <a href='/Movies/&actor=Tea Leoni'>Tea Leoni</a> Link to comment https://forums.phpfreaks.com/topic/187380-seperate-a-string/ Share on other sites More sharing options...
PravinS Posted January 6, 2010 Share Posted January 6, 2010 Use explode() function to separate. Link to comment https://forums.phpfreaks.com/topic/187380-seperate-a-string/#findComment-989478 Share on other sites More sharing options...
dreamwest Posted January 6, 2010 Author Share Posted January 6, 2010 It wont work, i have a varying number of deliminators Link to comment https://forums.phpfreaks.com/topic/187380-seperate-a-string/#findComment-989480 Share on other sites More sharing options...
rajivgonsalves Posted January 6, 2010 Share Posted January 6, 2010 its should consider the following <?php $string = 'Sam Neill|William H. Macy|Tea Leoni|'; foreach (explode('|', $string) as $name) { if (!(empty($name))) echo "<a href='/Movies/&actor=" . urlencode($name) ."'>$name</a><br />"; } ?> Link to comment https://forums.phpfreaks.com/topic/187380-seperate-a-string/#findComment-989484 Share on other sites More sharing options...
PravinS Posted January 6, 2010 Share Posted January 6, 2010 Use preg_split() function <?php $string = 'Sam Neill|William H. Macy|Tea Leoni|'; $keywords = preg_split("/[|$*]+/", $string); print_r($keywords); ?> Link to comment https://forums.phpfreaks.com/topic/187380-seperate-a-string/#findComment-989485 Share on other sites More sharing options...
trq Posted January 6, 2010 Share Posted January 6, 2010 It wont work, i have a varying number of deliminators You might want to give us a better description of your problem then? Link to comment https://forums.phpfreaks.com/topic/187380-seperate-a-string/#findComment-989497 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.