Expression Matching
STRING EXIST INSIDE THE STRING… we use the preg_match() function
< ? php
$string1= “Harshida D Parmar”;
If(preg_match(“/D/”,$string)) {
echo ”FOUNd”;
}
else
{
}
? >
Inside the if condition preg_match() function have two parameter.
First parameter have value which we want to search… With 2forthslashes “/”…And in middle of “//” the word which we want to search…
Second parameter is the Value/Variable from which the searching operation will going to perform…
This is very powerful function in php.
< ? php
function has_space($string)
{
If(preg_match(“/ /”,$string)) { //Search for white space.
Return true”;
}
else
{ return false;
}
}
$harshu=‘Thisisanonspaceexample’;
If (has_space($harshu))
{
Echo “”You need to add one space in the string”;
}
? >
No comments:
Post a Comment