Relative Content

Tag Archive for phpregex

Replace Apostrophe with PHP

I would like to replace an apostrophes in arbitrary text to html '. This seems to be a none trival exercise. I’d like to start by simplifiing the problem as follows:

RegEx in PHP: find the first matching string

I want to find the first matching string in a very very long text. I know I can use preg_grep() and take the first element of the returned array. But it is not efficient to do it like that if I only need the first match (or I know there is exactly only one match in advance). Any suggestion?