brown2005 Posted May 21, 2008 Share Posted May 21, 2008 word- this is a word meaning right what i want to do is put the above into a table... tword twordmeaning so i want to do is split the first line and put word into tword and word meaning into twordmeaning and not using the - or this is a Link to comment https://forums.phpfreaks.com/topic/106583-break-down-this/ Share on other sites More sharing options...
phpzone Posted May 21, 2008 Share Posted May 21, 2008 <?php $string = 'word- this is a word meaning'; $result = preg_replace('/(.*)-(.*)meaning/si', 't\1#t\1meaning', $string); list($word, $meaning) = split("#", $result); echo $word . '<br />'; echo $meaning . '<br />'; ?> may need some modification, but this will split the string you supplied. Link to comment https://forums.phpfreaks.com/topic/106583-break-down-this/#findComment-546390 Share on other sites More sharing options...
brown2005 Posted May 21, 2008 Author Share Posted May 21, 2008 thanks for your help.. i have used ur code above to get... $string = $websitesd; list($word, $meaning) = split("-", $string); $str = ucwords(preg_replace('"A piece of"','',$meaning)); $websites_add_sql = "INSERT INTO gold(id,name,meaning) VALUES ('','$word','$str')"; $websites_add_row = mysql_query($websites_add_sql); which puts everything into the table probably except for the meaning part has a space for it... any ideas how to avoid this please? Link to comment https://forums.phpfreaks.com/topic/106583-break-down-this/#findComment-546430 Share on other sites More sharing options...
BlueSkyIS Posted May 21, 2008 Share Posted May 21, 2008 use trim() to remove white space before and after a string. $a_string = " this is a string "; $a_string_trimmed = trim($a_string); echo $a_string_trimmed; output: this is a string Link to comment https://forums.phpfreaks.com/topic/106583-break-down-this/#findComment-546437 Share on other sites More sharing options...
brown2005 Posted May 21, 2008 Author Share Posted May 21, 2008 hi thanks for all the help so far... what i have noticed now is that on the end of the meaning part the is a . how can i get rid of this as well please? Link to comment https://forums.phpfreaks.com/topic/106583-break-down-this/#findComment-546462 Share on other sites More sharing options...
BlueSkyIS Posted May 21, 2008 Share Posted May 21, 2008 same function http://us2.php.net/trim Link to comment https://forums.phpfreaks.com/topic/106583-break-down-this/#findComment-546484 Share on other sites More sharing options...
phpzone Posted May 21, 2008 Share Posted May 21, 2008 I believe (from your earlier message to me) that you want code such as the following. If you have any variations on the examples in the $string array, you may need to tweak the preg_replace regular expression. Check www.regular-expressions.info for help with this. <?php $string = array('word- this is a word meaning.', 'oranges- these are delicious.', 'apples- these are green.' ); foreach( $string as $value ) { $result = preg_replace('/(.+)-.*\s(.*)\./si', '\1#\2', $value); list($word, $meaning) = split("#", $result); echo '<p>' . $word . ' = ' . $meaning . '</p>'; } ?> Link to comment https://forums.phpfreaks.com/topic/106583-break-down-this/#findComment-546544 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.