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);
Related
This question already has answers here:
Variable-length lookbehind-assertion alternatives for regular expressions
(5 answers)
Closed 4 years ago.
I cant get my regexpression to work in php. It works in javascript (vuejs):
(?<=.+: )(.*)
I have this string:
NL: abcdef
and i would like to get
abcdef
Can someone please tell me what i am doing wrong?
There are many ways to solve this using PHP/PCRE, one is to skip the preceding string using \K
[^:]+: \K(.*)
Regex Demo
If you can add an anchor to the beginning of the string, even better: ^[^:]+: \K(.*)
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:
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?
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How can I convert ereg expressions to preg in PHP?
I have upgraded php and now im getting the ereg_replace deprecated errors.
I have done some searching round web and found that I can use preg instead but not sure how to change this code correctly
$scriptName = ereg_replace(
"^".$_SERVER["DOCUMENT_ROOT"], "",
$_SERVER["SCRIPT_FILENAME"]
);
Replace the e with a p.
Add a delimiter to the beginning and end of that first argument. Traditionally, people use slashes (/), but I like to use ~ as there is less chance of actually using that character in the regular expression.
Just adding delimiters won't work when special characters are included in $_SERVER["DOCUMENT_ROOT"]'s value. You need to escape them as follows:
$scriptName = preg_replace(
"/^".preg_quote($_SERVER["DOCUMENT_ROOT"],"/")."/",
"",
$_SERVER["SCRIPT_FILENAME"]
);
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.