Jump to content

ajuda - replace


triplexim32
 Share

Recommended Posts

Estou a ter alguns problemas com o preg_replace.

Imaginemos que tenho estes exemplos:

<span style="font-weight: bold;">texto</span>
<span style="text-decoration: bold;">outro texto</span>

e quero transformar nisto

[span style="font-weight: bold;"]texto[/span]
[span style="text-decoration: bold;"]outro texto[/span]

da forma que tenho:

$message = preg_replace('/\<span style="(.+?)"\>(.+?)\<\/span>/', ' ', $message);

---------------------------

o problema surge quando eu tenho isto:

<span style="font-weight: bold;">qwe<span style="text-decoration: underline;">r</span></span>

fica transformado nisto:

[span style="font-weight: bold;"]qwer[/span]

---------------------------

O problema surge porque o preg apanhar o outro <span> que vem a seguir pois so acaba no proximo </span>

Eu precisava dum limitador para nao comer o outro span, ja tentei usar o ^  mas nao da  ?

---------------

Obrigado pela ajuda desde ja

<

Link to comment
Share on other sites

Não faz mal, porque fica aqui de referência para outros utilizadores com a mesma dúvida 😄

Não te esqueças é de carregar no botão Topic Solved, cá em baixo, para dizer que a questão está solucionada.

Nick antigo: softclean | Tens um projeto? | Wiki P@P

Ajuda a comunidade! Se encontrares algo de errado, usa a opção "Denunciar" por baixo de cada post.

Link to comment
Share on other sites

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
 Share

×
×
  • 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.