PHP regular expression - Text of a website

Asked

Viewed 37 times

0

I have a string

Value of the Cause: <'span id="i_valorCausa'">51.899,51<'/span'><'BR'>

I need to get what’s in between <'span id="i_valorCausa'> <'/span'>

I tried so:

The $content is where the string comes from.

preg_match_all("/<span id='i_valorCausa'>(.*)<\span>/", $content, $prices); 

echo $prices[1];

but it didn’t work. someone can help me?

Thanks in advance.

  • This html is a little weird. It has extra quotes/hairs, that’s right?

1 answer

1

you should put as an array like this: ($prices[1][0];)

$content = "<span id='i_valorCausa'>hduehuedheudheu<span>";

preg_match_all("/<span id='i_valorCausa'>(.*)<span>/", $content, $prices); 

echo $prices[1][0];

I took the test on that website

As it says in the documentation of PHP

Parameters Pattern The pattern to search for, as a string.

Subject The input string.

pouch Array of all combinations in multidimensional array ordered according to flags.

as you did not put flag, it will return in an array multidimensional

Browser other questions tagged

You are not signed in. Login or sign up in order to post.