1

Ok I tried to google it but couldn't find a solution so I am asking here. I am trying to save the HTML tags into a variable in php. I am trying to use preg_match but cannot find the right pattern(regex). I did find one regex '\s*(.*?)\s*>\s*'. This works ok on the functions-online site where I try it and gives me the whole tag i.e.i=<body> but when I try to run it in my programme I get

preg_match(): Delimiter must not be alphanumeric or backslash

It would be helpful if anyone could sort out this issue and even better if anyone could give the regex to get the data within the angle brackets(HTML tags)

Please also let me know if there is another method to store the html tags in php i.e.

<body>

then $var=body

Paul Hiemstra
  • 59,984
  • 12
  • 142
  • 149

2 Answers2

3
  1. RegEx match open tags except XHTML self-contained tags <-- Read the 1st answer if you are considering "parsing" HTML with regexes
  2. You need to add so called delimiters: '/\s*(.*?)\s*>\s*/'
Community
  • 1
  • 1
KillerX
  • 1,436
  • 1
  • 15
  • 23
0

Ok Thanx to the link provided by killerx I did find a regex which could be use but it is not the best method but should work for my task

'\'<([a-z]+)[^>]*(?<!/)>\''

This should work. It will get the full tag in an array and the tag description in the other. Thanx a ton for helping me out