Jump to content
xisto Community
Sign in to follow this  
Tom743

Php Preg Replace

Recommended Posts

Ive got a problem with preg replace, this is the code:

display.php

<table border="1"><tr><th width="70">Time</th><th width="200">IP</th><th width="70">Viewed</th></tr><?php$LogData = file_get_contents("log.txt");$Find = "/||(.*)|(.*)|(.*)||/i";$Replace = "<tr><td>$1</td><td>$2</td><td>$3</td></tr>";$Table = preg_replace($Find, $Replace, $LogData);print "$Table";?></table>

And this is whats in log.txt
||05-05-2008 12:08|127.0.0.1|1||||05-05-2008 12:00|127.0.0.1|1||||05-05-2008 12:00|127.0.0.1|1||

But it just displays like this.

http://forums.xisto.com/no_longer_exists/

Its ment to display it so that each one has its own row and is devided into colums.

Share this post


Link to post
Share on other sites

You need to remember that you are working with regular expressions. The vertical bar: | is a symbol used in regular expressions so it doesn't know that it wants you to look for those. What you want to do is escape all of those out. So change your find variable to this:

$Find = "/\|\|(.*)\|(.*)\|(.*)\|\|/i";

Share this post


Link to post
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
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.