homepage Welcome to WebmasterWorld Guest from 54.145.183.169
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP regular expression
orion_rus

10+ Year Member



 
Msg#: 11113 posted 4:50 pm on Dec 19, 2005 (gmt 0)

Hello world,
I have to ask you about preg_replace
i need to change <table> -> [table] and </table> -> [/table]
can i make it both in a one expression?
Thanks in advance!

 

DanA

10+ Year Member



 
Msg#: 11113 posted 5:51 pm on Dec 19, 2005 (gmt 0)

You can try this :
$test="<table>anytext</table>";
$patterns=array("/<table>/","/<\/table>/");
$replacements=array("[table]","[/table]");
$test=preg_replace($patterns,$replacements,$test);

ergophobe

WebmasterWorld Administrator ergophobe us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 11113 posted 6:35 am on Dec 20, 2005 (gmt 0)

Because </table> just is what it is, I would just use a str_replace().

For table, presumably you want something that can catch
<table class="someclass">

In that case, a pattern like

$pattern = '/<(table([^><]*>/U';

should work.

orion_rus

10+ Year Member



 
Msg#: 11113 posted 10:45 am on Dec 21, 2005 (gmt 0)

Thanks for answers!
It works great!

killroy

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 11113 posted 11:17 am on Dec 21, 2005 (gmt 0)

if u want a single pattern and replace for both jsut use this pattern:

\<(/?table(?: [^>]*))\>

and replace with <$1>

SN

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved