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!
Related
This question already has answers here:
How can I convert ereg expressions to preg in PHP?
(4 answers)
Closed 2 years ago.
I found one PHP script for get a database backup, there use this expression to do something, that script show call to undefined function ereg_replace() this error, if i remove this line script is working fine...
how to replace this function $row[$j] = ereg_replace("\n","\\n",$row[$j]); to that script working finely,
Can anyone assist me..
ereg_replace deprecated and remove from newer versions of php (7 and up).
You will have to update your code to use preg_replace
$row[$j] = preg_replace("#\n#","\\n",$row[$j]);
One of the differences between ereg_replace() and preg_replace() is that the pattern must be enclosed by delimiters: delimiter + pattern + delimiter, in this case we are using # so we don't have to escape / that is the usual that is used.
Valid Delimiters:
/, #, ~, +, %, #, ! , <, >
Reference from php.net
hope it helps.
This question already has answers here:
Replace preg_replace() e modifier with preg_replace_callback
(3 answers)
Closed 2 years ago.
ErrorException [ 8192 ]: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead
on
http://mastersoftwaretechnologies.com/kohana/index.php/user/login
This works in my kohana-3.2
Replace
$column = preg_replace('/"(.+?)"/e', '$this->quote_column("$1")', $column);
to
$column = preg_replace_callback('/"(.+?)"/', function($m) { return $this->quote_column($m[1]); }, $column);
In the file MODPATH/database/classes/kohana/database.php line 525
Looks like you are using php 5.5. If you want to use preg replace eval with it you have to modify it firts because it is deprecated due to security reasons: http://php.net/manual/en/migration55.deprecated.php
With php 5.5 you should use preg_replace_callback()
Good example you will find here: Replace deprecated preg_replace /e with preg_replace_callback
And info how it works here: Replace preg_replace() e modifier with preg_replace_callback
Just modify second paremeter accordingly to that what you want to do with matches.
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:
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);