Smarty Capitalize throws error: Deprecated: preg_replace(): The /e modifier [duplicate] - php

This question already has answers here:
Replace preg_replace() e modifier with preg_replace_callback
(3 answers)
Closed 5 years ago.
capitalize modifier in smarty throws error
{$payment.first_name|capitalize}
The above code throws the following error
Deprecated: preg_replace(): The /e modifier is deprecated, use
preg_replace_callback instead in
/home/mysuite/public_html/Demo/yoursite/includes/smarty/libs/plugins/modifier.capitalize.php
on line 65

You can use the php function ucwords like this.
{$payment.first_name|ucwords}
It might not work for non latin characters (not working on cyrillic) but than you can use some library and define your new function as smarty function.

Related

Why is my regex comparison returning a parse error in PHP [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Converting ereg expressions to preg
<?php
$searchtag = "google";
$link = "http://images.google.com/images?hl=de&q=$searchtag&btnG=Bilder-Suche&gbv=1";
$code = file_get_contents($link,'r');
ereg("imgurl=http://www.[A-Za-z0-9-]*.[A-Za-z]*[^.]*.[A-Za-z]*", $code, $img);
ereg("http://(.*)", $img[0], $img_pic);
echo '<img src="'.$img_pic[0].'" width="70" height="70">'; ?>
And i get this error
Deprecated: Function ereg() is deprecated in C:\Program Files\EasyPHP-5.3.8.1\www\m\img.php on line 5
Deprecated: Function ereg() is deprecated in C:\Program Files\EasyPHP-5.3.8.1\www\m\img.php on line 6
preg_match() functions give this error
Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in C:\Program Files\EasyPHP-5.3.8.1\www\m\img.php on line 6
Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in C:\Program Files\EasyPHP-5.3.8.1\www\m\img.php on line 7
ereg is deprecated. Don't use it.
The preg functions are all "Perl regular expressions" meaning you need to have some sort of beginning and end marker on your regex. Often this will be / or #, but any non alpha-numeric will do fine.
For example, these will work:
preg_match("/foo/u",$needle,$haystack);
preg_match("#foo#i",$needle,$haystack);
preg_match("#foo#",$needle,$haystack);
preg_match("\$foo\$w",$needle,$haystack); // bad idea because `$` means something
// in regex but it is valid anyway
// also, they need to be escaped since
// I'm using " instead of '
But this will not:
preg_match("foo",$needle,$haystack); // no delimiter!
With preg_match() your regex must begin and end with a delimiter such as / with few exceptions (for example adding "i" at the end for case-insensative).
e.g.
preg_match('/[regex]/i', $string)

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback in Echelon B3 [duplicate]

This question already has answers here:
Replace preg_replace() e modifier with preg_replace_callback
(3 answers)
Closed 4 years ago.
function removeColorCode($text) {
return preg_replace('/\\^([0-9])/ie', '', $text);
}
The above code gives a deprecation warning on Echelon B3 i think after upgrading to PHP 5.5.29 by our host provider
How can I replace the code properly with preg_replace_callback()?
In this specific case, just remove the /e it does nothing here.
You can also remove the /i
So your code becomes:
function removeColorCode($text) {
return preg_replace('/\^[0-9]/', '', $text);
}

Change preg_replace into preg_replace_callback [duplicate]

This question already has answers here:
Replace preg_replace() e modifier with preg_replace_callback
(3 answers)
Closed 7 years ago.
I'm trying to replace the following string:
\u0080\u009cone hand rule\u0080\u009d
As I have to replace those codes for many strings and as there are various combinations of \u0080\u009 like \u00e2\u0080\u0099 and \u00a0 I ve searched for an solution to convert them all back into their according value.
The solution i ve found was posted on this site: http://www.avoid.org/replace-u-characters-in-json-string/
preg_replace("/\\\\u([a-f0-9]{4})/e",
"iconv('UCS-4LE','UTF-8', pack('V', hexdec('U$1')))",
json_encode($struct));
As i was trying to use this code php threw the following error:
Deprecated: preg_replace(): The /e modifier is deprecated, use
preg_replace_callback instead
Since I'm relativley new to php i bareley understand the preg_replace in first place but with the conversion to preg_replace_callback i'm totally overstrained. I've looked up How to convert preg_replace e to preg_replace_callback? but i didnt get it :/
Could somone pls explain how to convert my preg_replace into preg_replace_callback?
The code I m trying to get to work looks now like this:
$string = preg_replace("/\\\\u([a-f0-9]{4})",
function($match){
return = iconv('UCS-4LE','UTF-8',pack('V', hexdec('U$1')), $match[1]);
},
json_encode($string));
I ve read and understood how to access my found matches but since the
"iconv('UCS-4LE','UTF-8', pack('V', hexdec('U$1')))",
from the original code doesnt access any of the matches found I'm quiet confused how to set up my anonymous function
As of PHP 5.5.0 E_DEPRECATED level error is emitted when passing in the "\e" modifier. As of PHP 7.0.0 E_WARNING is emited in this case and "\e" modifier has no effect.
Please visit preg_replace and preg_replace_callback for documentation
"/\\u([a-f0-9]{4})" = > "/\\u([a-f0-9]{4})/"

Kohana preg_replace error in database.php [duplicate]

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.

regex error preg_replace_callback() : Unknown modifier '.' in [duplicate]

This question already has answers here:
Warning: preg_replace(): Unknown modifier
(3 answers)
Closed 3 years ago.
I got the following string:
last_name, first_name
bjorge, philip
kardashian, [kghim]
mer#$##Code:menu:51587daa7030e##$#cury some more
data #$##Code:menu:515r4387daa7dsf030e##$#, freddie
im trying to replace the Codes in the middle with the function: 'codeParser' the regex is:
$PC_File = preg_replace_callback("(?=\#\$\#\#).*?(?<=\#\#\$\#)", 'codeParser', $PC_File);
but getting this error:
PHP Warning: preg_replace_callback() : Unknown modifier '.'
You need to wrap your regular expression in delimiters. It's considering () to be the delimiters right now, and the . as a modifier (which is of course invalid).
"/(?=#\\$##).*?(?<=##\\$#)/"
(I'm also pretty sure the # do not need to be escaped unless you were using them as delimiters)
EDIT: You need \\ to properly escape the $ in double-quotes.

Categories