Jump to content

break down this


brown2005

Recommended Posts

<?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

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

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

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.