Jump to content

Help with regexp in PHP


Artiom

Recommended Posts

[code]
<?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;

?>
[/code]
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\:]+)
Link to comment
https://forums.phpfreaks.com/topic/24052-help-with-regexp-in-php/
Share on other sites

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

[code]
<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>
[/code]

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.