Jump to content

break down this


brown2005

Recommended Posts

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
Share on other sites

<?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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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