Jump to content

[SOLVED] [PCRE] Find and replace <? with <?php


Vinze

Recommended Posts

Hey, I want to use preg_replace() to replace all instances of <? with <?php. I can't do this with str_replace() because when I [i]do[/i] use <?php it would be converted to <?phpphp. I tried the following pattern:
[code]
[<\?(!(php))][/code]

But that doesn't work. Please help me, thanks in advance.

[b]Edit:[/b] And I learned something new today: lookaheads. The correct code was:

[code]
[<\?(?!php)][/code]
Link to comment
https://forums.phpfreaks.com/topic/31676-solved-pcre-find-and-replace/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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