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
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.