wrap -tag around first word of string with preg_replace

后端 未结 3 1956
既然无缘
既然无缘 2021-01-13 20:07

My problem is, that this:

preg_replace(\'/(?<=\\>)\\b\\w*\\b|^\\w*\\b/\', \'$&\', $string);

Does not work and

3条回答
  •  独厮守ぢ
    2021-01-13 20:14

    Try with this instead

    preg_replace('/(?<=\>)\b\w*\b|^\w*\b/', '$0', $string);
    

    $0 means it will become the first thing matched in your regex, $1 will become the second etc.

    You could also use back-references; \0 gets the first thing matched back from where you are, \1 gets the second thing matched back etc. More Info

提交回复
热议问题