0

Have to split a text by an dynamic id f.e.

My regex:

$content = preg_split('/<span id="more-[1-9]+"><\/span>/i', get_the_content('more'));

Unfortunately sometimes it works, sometimes not:

<span id="more-1237"></span> -> it works

<span id="more-1029"></span> -> not working

whats wrong, thanks for help

nickb
  • 59,313
  • 13
  • 108
  • 143
Stiller Eugen
  • 681
  • 2
  • 10
  • 28

1 Answers1

2

Your second example has a zero in the digits after more-, which your regex won't match. You need something like:

$content = preg_split('/<span id="more-[0-9]+"><\/span>/i', get_the_content('more'));

Note the change from [1-9] to [0-9].

nickb
  • 59,313
  • 13
  • 108
  • 143