Jump to content

Recommended Posts

Posted

Viva, estou a tentar obter o código contido entre duas tags:

php

preg_match_all('<!--beginMenu-->(.*?)<!--endMenu-->',$HTML,$output);

html

<!--beginMenu-->
Olá eu sou o código que devia aparecer no $output.
<!--endMenu-->

O que está mal no preg match? tks

Posted
preg_match_all('#<!--beginMenu-->(.*)<!--endMenu-->#s', $HTML, $output);

Se a ideia for apanhar conteúdo entre múltiplas tags, isto não funciona. Se for só uma, já funciona.

Posted

Para além de não colocares nenhum delimiter na tua expressão, esqueceste-te do s depois do closing delimiter para indicar o "suporte" a newlines. 😞

EDIT: Como o Nazgulled mostrou. ^^

I intend to live forever. So far so good.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. 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.