0

Possible Duplicate:
How to parse and process HTML with PHP?

I expect this one to return (bool)True or int(1)

echo var_dump(preg_match('/(<[tT][eE][xX][tT][aA][rR][eE][aA][^<>]*>)(.*?)(<\/[tT][eE][xX][tT][aA][rR][eE][aA]>)/', 
    "<textarea id='field-static_content' name='static_content' class='texteditor' ><p>
any content<p></textarea>"));

But I get int(0) as a result. I try to match any string with "<textarea" (non case sensitive) followed by any other character but "<" and ">", followed by ">", followed by any other character, and then ended by "</textarea>" non case sensitive

Do anyone know what's wrong with my regex pattern?

Community
  • 1
  • 1
goFrendiAsgard
  • 4,016
  • 8
  • 38
  • 64
  • 1
    RegEx are not reliable for parsing HTML. Instead use parser such as simplehtmldom http://simplehtmldom.sourceforge.net/ – Dr. Dan Nov 27 '12 at 10:24
  • 1
    Read: http://stackoverflow.com/questions/3577641/how-to-parse-and-process-html-with-php – Chris Nov 27 '12 at 10:24
  • Parse this string, but in the future, don't use `[tT][eE]` thingy's to make a patterns case-insensitive, instead use `'/textarea/i'`<-- the i is the case-Insensitive flag, also: it's important to know that neigh on _every_ char has a special meaning depending on the context in which it's used, not in the least `<` and `>`, which you seem to forget – Elias Van Ootegem Nov 27 '12 at 10:28

2 Answers2

1

It's the line break. Check Pattern Modifier, 's' and also 'i'.

steffen
  • 16,138
  • 4
  • 42
  • 81
0

You are missing the /s flag. Your input text contains a linebreak, which is why .*? won't find it per default.

More importantly you are missing the /i flag for case-insensitivity. No need to write [aA][bB]...

mario
  • 144,265
  • 20
  • 237
  • 291