hello;
I would like to determine if substring exists within a string;
$substring = 'poiuy';
$string='_okmn_wwwwwww_poiuy_asasasasas';
is $substring inside of $string?
thank you
Shannon Burnett
finding a substring inside a string
Moderator: General Moderators
- mudkicker
- Forum Contributor
- Posts: 479
- Joined: Wed Jul 09, 2003 6:11 pm
- Location: Istanbul, TR
- Contact:
[php_man]ereg[/php_man] function or [php_man]substr_count[/php_man] function would help you.
Code: Select all
<?php
if(substr_count($text,$stringtofind) > 0) {
echo "yes it is in it.";
}
// or
if (eregi($stringtofind, $text)) {
echo "$text contains - $stringtofind!";
}
?>Re: finding a substring inside a string
Code: Select all
<?php
$substring = 'poiuy';
$string='_okmn_wwwwwww_poiuy_asasasasas';
if(strstr($string, $substring))
{
echo 'String was found!';
}
?>I appreciate everyone's responses;
I had looked at these but was swayed away from them because their respective examples were seemingly all discussing single character needles;
I have already started a function that will parse each $string and $substring into arrays, determine first pos in string that matches first character in substring, then determines if all subsequent characters in $string match the subsequent characters in $substring;
I like strpos() better; I should have tested to see if needle could be a multi-character string a couple of hours ago;
thanks
dsdsdsdsd
I had looked at these but was swayed away from them because their respective examples were seemingly all discussing single character needles;
I have already started a function that will parse each $string and $substring into arrays, determine first pos in string that matches first character in substring, then determines if all subsequent characters in $string match the subsequent characters in $substring;
I like strpos() better; I should have tested to see if needle could be a multi-character string a couple of hours ago;
thanks
dsdsdsdsd