Reputation: 2700
I am not good at writing php regex, now some data like searchword&num=10
I want use preg replace remove &num=10
or sometimes it could be &num=10
, thanks.
echo preg_replace(array('/\&num=(d+)/i','/(&)num=(d+)/i'),'','searchword&num=10');
//I would like to only get searchword
Upvotes: 0
Views: 169
Reputation: 7821
You can use html_entity_decode
to your advantage here.
$searchStr = html_entity_decode($searchStr);
echo preg_replace('/\&num=\d+/i', '', '$searchStr);
Although, you can simply use substr like this
echo substr($searchStr, strpos('&'));
Upvotes: 1
Reputation: 32158
What about a regex that will match anything from the beginning of the string up to the first ampersand ?
/^[^\&]+/
Upvotes: 1