Jump to content

propellerhead

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

propellerhead's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Well yes, since the custom tags will be used in a xhtml environment. Is there a way how to extract all of the custom blocks, not just the last?
  2. explode won't work because the <custom> tag is just for an example. The nature of the application requires it to be parsed using regular expression because the attributes that will be placed inside the custom tag <custom attr1="blah" attr2="blah">, and the large content.
  3. Hi. I'm new with regular expressions so this may not be a big deal for you, but I'm stuck for hours on this bit and I can't find the solution. Here I go: I have a string of this kind <custom> probe1 <custom> probe2 </custom> probe3 </custom> <custom> probe4 </custom> <custom> probe5 </custom> I'm trying to match only those custom tags that don't have child (custom) tags in them, so I use this regex /<custom>((?!.*<custom>).*)<\/custom>/s and so, it looks fine on first sight, but there is a problem. When I make the match using preg_match_all it onlly returns the last matching pattern <custom> probe5 </custom> here is the array dump using print_r Array ( [0] => Array ( [0] => <custom> probe5 </custom> [1] => probe5 ) ) How do I fix this? I know that there must be something wrong with the regex, but my knowledge in this field is limited and I can't find the solution. Here is the whole code <?php $string = " <custom> probe1 <custom> probe2 </custom> probe3 </custom> <custom> probe4 </custom> <custom> probe5 </custom>"; $regex = "/<custom>((?!.*<custom>).*)<\/custom>/s"; preg_match_all($regex, $string, $arry, PREG_SET_ORDER); print_r($arry); ?> I'd be very very thankful
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.