How can I test if string start with "<" and end with ">" and print true if that true.
$Text="<hi how are you>"; // true
$Text=" any <hi how are you>"; // false
$Text="<hi how are you> any"; // false
Printable View
How can I test if string start with "<" and end with ">" and print true if that true.
$Text="<hi how are you>"; // true
$Text=" any <hi how are you>"; // false
$Text="<hi how are you> any"; // false
Like this:
Edit: Changed code.Code:$s[] = "<boooam>asdf";
$s[] = "abbb<aoom>";
$s[] = "<funk>";
for ($i = 0; $i < count($s); $i++) {
if (preg_match("/^<(.*)>$/i", $s[$i])) {
echo htmlspecialchars($s[$i]) . " : true<br>\n";
} else {
echo htmlspecialchars($s[$i]) . ": false<br>\n";
}
}
here we go again :p
lol, that was my first reaction, too. :DQuote:
Originally posted by phpman
here we go again :p
Another method:
Of course you could also loop through an array, with this function, similar to how Hobo did it above.PHP Code:$text="<hi how are you>";
if(substr($text,0,1) == "<" && substr($text,-1) == ">")
echo "True<br>";
else
echo "False<br>";
$text=" any <hi how are you>"; // false
if(substr($text,0,1)=="<" && substr($text,-1)==">")
echo "True<br>";
else
echo "False<br>";
$text="<hi how are you> any"; // false
if(substr($text,0,1)=="<" && substr($text,-1)==">")
echo "True<br>";
else
echo "False<br>";
s.