Jump to content


Photo

Help with regexp in PHP


  • Please log in to reply
2 replies to this topic

#1 Artiom

Artiom
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 16 October 2006 - 03:52 AM

<?php
$d="INSERT INTO PlaceholderInfo(PlaceholderInfoID, MsgClassName, Placeholder, Description, Sample, ListPrefix, UserArc, DateArc )
VALUES (5,'Trouble Ticket Notification','Ticket_Level_Description','General ticketinfo : Description of ticket Support Level','Front Level of Support',NULL,0,0);";
$a=addslashes("VALUES\s\([\d]+,'([\w\s\d]+)','[\w\s\d]+','([\w\s\d\:]+)");
ereg ('VALUES\s\([\d]+\',\'([\w\s\d]+)\',\'[\w\s\d]+\',\'([\w\s\d\:]+)', $d, $regs);
echo "$regs[2] $regs[1]";
//echo $a;

?>
I have a code, the goal is to get the second and fourth elements from the DB querry. As the result of operation $regs should contain the necessary elements, but it is empty :(
I've checked the regular expression in Espresso - it works just fine. Hepl please!

Pure regexsp as I had checked in Espresso
VALUES\s\([\d]+\',\'([\w\s\d]+)\',\'[\w\s\d]+\',\'([\w\s\d\:]+)

#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 16 October 2006 - 02:57 PM

ereg does not support \s, \d or \w: use preg.

<pre>
<?php

$d="INSERT INTO PlaceholderInfo(PlaceholderInfoID, MsgClassName, Placeholder, Description, Sample, ListPrefix, UserArc, DateArc )
VALUES (5,'Trouble Ticket Notification','Ticket_Level_Description','General ticketinfo : Description of ticket Support Level','Front Level of Support',NULL,0,0);";

preg_match('%VALUES\s\(\d+,\'([\w\s\d]+)\',\'[\w\s\d]+\',\'([\w\s\d\:]+)%', $d, $regs);
print_r($regs);
?>
</pre>

Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 Artiom

Artiom
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 17 October 2006 - 05:31 AM

Wow, million of thanx! This works just fine!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users