How to migrate php preg_replace to preg_replace_callback? [duplicate] - php

This question already has answers here:
Replace preg_replace() e modifier with preg_replace_callback
(3 answers)
Closed 1 year ago.
Given line:
"$className = "MForm" . preg_replace('/(?:^|_)(.?)/e',"strtoupper('$1')",$name);"
isn't working with PHP7. I changed it to:
"$className = "MForm" . preg_replace_callback('/(?:^|_)(.?)/',"strtoupper('$1')",$name);"
It seems not to be correct, due to warning printout:
"Warning: preg_replace_callback(): Requires argument 2, 'strtoupper('$1')', to be a valid callback in /.../components/com_proforms/formlib/init.php on line 59"
How can I handle strtoupper('$1') correctly in preg_replace_callback()?

Replace "strtoupper('$1')" with
function($matches) { return strtoupper($matches[1]); }
No quotes around it.

Related

Eregi replace to? [duplicate]

This question already has answers here:
Alternative for deprecated PHP function: eregi_replace [duplicate]
(2 answers)
Closed last year.
can someone show me how to convert this please
eregi_replace(":rolleyes:", "<img src='./images/smilies/icon_rolleyes.gif' border='0'> ", $
i have tried lookin gonline but carnt get my head around it keep getting this error
keep getting
PHP Deprecated: Function eregi_replace() is deprecated in
The eregi_replace function is deprecated as of PHP 5.3. You should use preg_replace with the i modifier instead:
preg_replace('/:rolleyes:/i', '<img src="./images/smilies/icon_rolleyes.gif" border="0">', $var);

Strict Standards: Only variables should be passed by reference preg_replace [duplicate]

This question already has an answer here:
reset() - "Strict Standards: Only variables should be passed by reference" [duplicate]
(1 answer)
Closed 3 years ago.
I am new to Mysqli_* and I am getting these errors:
(PHP 4 >= 4.0.5, PHP 5, PHP 7)
preg_replace_callback — Perform a regular expression search and replace using a callback
$url = preg_replace('/\/index.php$/i', '', reset($url = explode('?', $_SERVER['HTTP_REFERER'])));
I've read the PHP site and I am just not seeing something. I've tried using preg_replace_callback and splitting the striing and still not working.
There's no need for the call to reset(), just put the call to explode() there.
$url = preg_replace('/\/index\.php$/i', '', explode('?', $_SERVER['HTTP_REFERER']));

What to replace eregi() with? [duplicate]

This question already has answers here:
ereg/eregi replacement for PHP 5.3 [duplicate]
(4 answers)
Closed 5 years ago.
What is eregi() replaced with in this instance?
// get value of text inbetween tags
function getContentByTag($tag1, $tag2, $string)
{
if (eregi("$tag1(.*)$tag2", $string, $out)) {
$outdata = $out[1];
}
return $outdata;
}
This post is not a duplicate post as the 3rd example within the referenced post the answer is for that specific usage. I'm guessing my usage is different as the referenced post answers are not working for me.
Since PHP 7 you must replace it with
preg_match("/$tag1(.*)$tag2/i", $string, $out)

Fatal error: Uncaught Error: Call to undefined function ereg_replace() PHP 7 [duplicate]

This question already has answers here:
How can I convert ereg expressions to preg in PHP?
(4 answers)
Closed 3 years ago.
below code is giving me the fatal error in php 7
$jquery_click_hook = ereg_replace("[^A-Za-z0-9]", "", strtolower($value['name']));
is there any way to make it compatible with php 7?
Switch to preg_replaceDocs and update the expression to use preg syntax (PCRE) instead of ereg syntax (POSIX) where there are differencesDocs (just as it says to do in the manual for ereg_replaceDocs).
Your above code should be this way:
$jquery_click_hook = preg_replace("[^A-Za-z0-9]", "", strtolower($value['name']));
ereg_replace function was DEPRECATED in PHP 5.3.0, and REMOVED in PHP 7.0.0. So you must have to use preg_replace() function instead of ereg_replace()

I need assistance with eregi - preg_match [duplicate]

This question already has answers here:
How can I convert ereg expressions to preg in PHP?
(4 answers)
Closed 7 years ago.
I was getting the following error:
Deprecated: Function eregi() is deprecated in /home/herbalhe/public_html/admin/includes/auth.inc.php
So I searched and found that I should be using preg_match() instead of eregi(). So I made the changes and now I am getting this error:
Warning: preg_match(): Unknown modifier 'p' in /home/herbalhe/public_html/admin/includes/auth.inc.php
The code on that line is:
if (preg_match(".inc.php",$HTTP_SERVER_VARS['PHP_SELF']) ||
preg_match(".inc.php",$_SERVER['PHP_SELF']))
Any idea what I should now?
It should be:
preg_match("/\.inc\.php$/i", $HTTP_SERVER_VARS['PHP_SELF'])

Categories