Jump to content

Archived

This topic is now archived and is closed to further replies.

martian2k4

Help me please :(

Recommended Posts

Hey, I need to check a string to see if it contains a work, for example



$str = "Ham Pizza";

if ( $str contains Ham ) {

echo "the pizza was ham";

}




Please help :D. Thanks

Share this post


Link to post
Share on other sites
[code]
<?

$str = "Pizza";


if ( $str == 'Ham') {

echo "the ".$str." was ham";

}
?>
[/code]

or

[code]

$str = "Ham Pizza";

if (! $str ) {

echo "the pizza was ham";

}

[/code]


I think thats right try

good luck.

Share this post


Link to post
Share on other sites
You might want to look at [a href=\"http://uk2.php.net/manual/en/function.strpos.php\" target=\"_blank\"]strpost[/a] or if you have PHP5 available use [a href=\"http://uk2.php.net/manual/en/function.stripos.php\" target=\"_blank\"]stripost[/a] for a case insensitive search.

For a more accurate search you may want to use [a href=\"http://uk2.php.net/manual/en/function.preg-match.php\" target=\"_blank\"]preg_match[/a]

Share this post


Link to post
Share on other sites
That would be the function strpos(), not strpost().

Ken

Share this post


Link to post
Share on other sites

×

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.