|
-
Feb 13th, 2003, 08:00 AM
#1
Thread Starter
Hyperactive Member
Start With and End With
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
-
Feb 13th, 2003, 03:17 PM
#2
Stuck in the 80s
Like this:
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";
}
}
Edit: Changed code.
Last edited by The Hobo; Feb 13th, 2003 at 03:28 PM.
-
Feb 13th, 2003, 04:38 PM
#3
Frenzied Member
here we go again
-
Feb 13th, 2003, 05:25 PM
#4
Stuck in the 80s
Originally posted by phpman
here we go again
lol, that was my first reaction, too.
-
Feb 14th, 2003, 05:37 AM
#5
Registered User
Another method:
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>";
Of course you could also loop through an array, with this function, similar to how Hobo did it above.
s.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|