View Full Version : Matching "*" using preg_match. Please help.
12-07-2010, 06:38 AM
I need to search for "*" in $value. The below code is not matching. Please help.
echo "* is selected<br>";
12-07-2010, 06:43 AM
See http://www.php.net/preg_quote for a list of characters that must be escaped, or "quoted", to be literally matched.
preg_match( '/(\*)/', $value )
If all you're doing is checking for asterisks, or an asterisk count, it'll be much more efficient to use strpos() or substr_count():
if ( FALSE !== strpos( $value, '*' ) )
echo 'found at least one asterisk';
$asterisk_count = substr_count( $value, '*' );
if ( $asterisk_count > 0 )
echo 'number of asterisks found: ' . $asterisk_count;
12-07-2010, 08:32 AM
Thanks buddy... it solved the issue.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.