This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How can I convert ereg expressions to preg in PHP?
I am getting the above (subject) error from:
if (ereg('<coordinates>([0-9.-]{1,}),([0-9.-]{1,}).*</coordinates>', $result, $regs))
So I did this:
if (preg_match('<coordinates>/[0-9.-]{1,}\/,\/[0-9.-]{1,}/.*</coordinates>/', $result, $regs))
Now the Google map doesn't show up at all and it also warns "..cannot find coordinates..."
Where did I go wrong?
Thanks!
You need delimiters around your pattern when using PCRE functions:
if (preg_match('~<coordinates>/[0-9.-]{1,}\/,\/[0-9.-]{1,}/.*</coordinates>/~', $result, $regs))
Notice the ~ at the beginning and end.
Normally, people use / as a delimiter, but because it shows up so frequently in your pattern, an alternate delimiter has been selected.
As #nickb mentioned, have a look at this discussion:
How can I convert ereg expressions to preg in PHP?
Related
This question already has answers here:
How can I convert ereg expressions to preg in PHP?
(4 answers)
Closed 9 years ago.
Hi I have the following code that that uses the eregi() function that PHP is saying is depreciated. I am trying to convert it into a replacement function (preg match) but im not too sure how to go about it as I am new to preg match function.
eregi ('^[[:alnum:]][a-z0-9_\.\-]*#[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['email'])))
How can I layout the above code in the preg match function?
Thanks
filter_var(stripslashes(trim($_POST['email'])), FILTER_VALIDATE_EMAIL)
will do the task you are trying to complete, and it validates email addresses even better ;)
Otherwise use preg_match and replace [:alnum:] with [0-9A-Za-z] in the pattern.
See
filter_var
List of validate filters
This question already has answers here:
How can I convert ereg expressions to preg in PHP?
(4 answers)
Closed 8 years ago.
I'm using PHP 5.2.17. I want to remove some surplus data from a JSON string and I've thought I can use some replace function to do so. Specifically I'm using ereg_replace with the next expression:
'^.*?(?=\"created_at)'
Which I've validated at http://www.regexpal.com. I've pasted my JSON string in there and the match is right. However, when I make the call:
$tweets = eregi_replace('^.*?(?=\"created_at)', $temp, 'something');
and then I echo the $tweets variable, there's output. No errors in console neither. Apache error log, however, complains about an error called REG_BADRPT. There's a comment in the php docs of eregi_replace suggesting this can be due to I need to escape special characters, but I've already escaped the " character. And I've tried to escape others but no different behavior.
Where could the problem be then?
I don't think that ereg supports lookarounds. preg_replace exists in php 5.2, so you should really use that instead. It will work with your expression with delimiters.
$tweets = preg_replace('#^.*?(?=\"created_at)#i', 'something', $temp);
As other people have pointed out, ereg functions are deprecated, so use preg_replace. You also have to encapsulate your regex string in slashes (/). You can put your regex flags after your last slash.
This question already has answers here:
How can I convert ereg expressions to preg in PHP?
(4 answers)
Closed 3 years ago.
I am getting the following error when running on PHP 5.3.8
Deprecated: Function eregi_replace() is deprecated in
/home/XXXXXX/public_html/admin/modifypoll.php on line 49
This is the line of code, can anyone help please
$question = eregi_replace('</?[a-z][a-z0-9]*[^<>]*>', '', $question );
I am not sure what to change it to.
Can anyone help please
the entire ereg family of functions are deprecated in PHP and will at some point be removed from the language. The replacement is the preg family. For the most part, the change is simple:
preg_replace('/[^<>]>/i', '', $question);
^-- ^ ^^
change ereg to preg
add delimeters (/)
for case insensitive matches (eregi), add the i modifier
$question = preg_replace('/<\/?[a-z][a-z0-9]*[^<>]*>/i', '', $question);
By the way, you can simply use $question = strip_tags($question); to achieve the same without any regexes!
This question already has answers here:
How can I convert ereg expressions to preg in PHP?
(4 answers)
Closed 3 years ago.
I am replacing PHP deprecated functions in my website. I have this code:
(eregi("<[^>]*object.*\"?[^>]*>", $secvalue))
It is written on the php.net site that it eregi should be replaced with preg_match with i modifier.
Is this coded right?
(preg_match("<[^>]*object.*\"?[^>]*/i>", $secvalue))
or should I place /i somewhere else?
preg_match('/<[^>]*object.*\"?[^>]*>/i', $secvalue)
You need to add a forward slash at the beginning to match the closing one:
preg_match('/<[^>]object."?[^>]*>/i', $secvalue);
This question already has answers here:
How can I convert ereg expressions to preg in PHP?
(4 answers)
Closed 3 years ago.
I need this php code changed to preg_match please
if(eregi("someurl",$data))
if (preg_match('~someurl~i', $data)). Delimiters can be any single character — I've used ~ instead of / used in examples on PHP site, because if you're putting URL in there, you'd have to escape /. i after the second delimiter is a flag triggering case-insensitivity — PCRE doesn't have separate functions for that.