0

I am trying to parse some text and retrieve info inbetween two strings. The regex seems to be fine, but I still do not get any result.

The text string looks like this: ""<h1 class="csc-firstHeader">Text I want to retrieve</h1></header>

The php code I am using:

$start = preg_quote('Header">', '/'); 
$end = preg_quote('</h1>', '/');

$regex = '#'.$start.'(.*?)'.$end.'#';
echo $regex;

$code = preg_match($regex, $text, $matches);

print_r($code);
print_r($matches);

The result is unfortunately empty.

merlin
  • 2,717
  • 3
  • 29
  • 59

1 Answers1

0

You don't need to escape / if you're using # for your regex delimiters. The second parameter for preg_quote is your regex delimiter, which means your code should have been:

$start = preg_quote('some_text', '#'); 
$end = preg_quote('some_other_text', '#');
Mr. Llama
  • 20,202
  • 2
  • 62
  • 115
  • This unfortunately does not work either. The regex itself works if I test it with online tools but it does not work with php – merlin Jan 25 '16 at 21:24