Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Php Preg Replace
Tom743
post May 5 2008, 11:47 AM
Post #1


Newbie
*

Group: Members
Posts: 7
Joined: 12-January 08
Member No.: 56,132



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

display.php
CODE
<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
CODE
||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://www.tehupload.com/8758642822.png

Its ment to display it so that each one has its own row and is devided into colums.
Go to the top of the page
 
+Quote Post
galexcd
post May 5 2008, 05:50 PM
Post #2


Define:EVIL PROGRAMMER (ē'vəl prō'grăm'ər)- n. An organism that converts caffeine into evil software.
*********

Group: [HOSTED]
Posts: 975
Joined: 25-September 05
From: The dungeon deep below the foundation of trap17
Member No.: 12,251



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:
CODE
$Find = "/\|\|(.*)\|(.*)\|(.*)\|\|/i";
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Regexp Function Preg_match_all()(0)
  2. Replace A Character In A Specific Tag(7)
  3. Help With Preg_replace(3)
  4. Preg_replace Problems(7)
  5. Validation Script - Detecting Illegal Characters(0)
  6. Preg Replace Problem(1)
  7. A Simple Preg_replace Help Please.(1)


 



- Lo-Fi Version Time is now: 25th July 2008 - 10:52 AM