jd2007 Posted September 30, 2007 Share Posted September 30, 2007 $string="<form method='get' action='script.php'></form>"; $regex="<form\s"; echo (preg_match($regex, $string)) ? 1 : 0; i want it to show 1 if <form\s is found. what i get is this: Warning: preg_match() [function.preg-match]: No ending matching delimiter '>' found in C:\AppServ\www\regex1.php on line 5 0 Link to comment https://forums.phpfreaks.com/topic/71225-why-do-i-get-error-below-preg_match/ Share on other sites More sharing options...
sKunKbad Posted September 30, 2007 Share Posted September 30, 2007 you have specified that your delimiter is a less than sign. You should have done this: $regex = "|<form\s|"; Link to comment https://forums.phpfreaks.com/topic/71225-why-do-i-get-error-below-preg_match/#findComment-358272 Share on other sites More sharing options...
sKunKbad Posted September 30, 2007 Share Posted September 30, 2007 It probably oughta be something like this: if (preg_match('/^\\<form\\s\\z/', $string)) { echo "1"; } else { echo "no match found"; } Link to comment https://forums.phpfreaks.com/topic/71225-why-do-i-get-error-below-preg_match/#findComment-358273 Share on other sites More sharing options...
jd2007 Posted September 30, 2007 Author Share Posted September 30, 2007 you have specified that your delimiter is a less than sign. You should have done this: $regex = "|<form\s|"; why do i need to use the | ? Link to comment https://forums.phpfreaks.com/topic/71225-why-do-i-get-error-below-preg_match/#findComment-358291 Share on other sites More sharing options...
xylex Posted September 30, 2007 Share Posted September 30, 2007 You need to use some character to denote the start and end of a regular expression within your string. "|" and "/" are common characters to use, but you can use almost any character. The first charcter in the string your original code has is "<" so the error message you posted is from not being able to find the matched closing charcter. Link to comment https://forums.phpfreaks.com/topic/71225-why-do-i-get-error-below-preg_match/#findComment-358309 Share on other sites More sharing options...
jd2007 Posted September 30, 2007 Author Share Posted September 30, 2007 thanks Link to comment https://forums.phpfreaks.com/topic/71225-why-do-i-get-error-below-preg_match/#findComment-358321 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.