This question already has answers here:
How can I convert ereg expressions to preg in PHP?
(4 answers)
Closed 4 years ago.
I've read many threads here about this being deprecated and tried replacing it with preg_match but I don't know php enough to fix the rest of the line.
Been enjoying Fotoholder for years, I would switch to a newer similar single file gallery code but then I would lose all my descriptions in the gallery.
Please help resurrect Fotopholder!
( https://github.com/offsky/Fotopholder )
Here are the 2 parts that have eregi:
if(substr($entry,0,1)!="." && !preg_match("#_cache#i",$entry) && is_dir($path."/".$entry)) {
and the 2nd eregi:
if(substr($entry,0,1)!="." && !eregi("_cache",$entry)) {
Thank you very much for your help.
Deprecated means, that the function eregi() is likely to get deleted from the language.
Please use preg_match().
While you still can use eregi(), at a certain point of time your application might not be able to execute any more.
That said: Your code posted is far to big to get a detailed answer.
Related
This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
Closed 3 years ago.
My company has asked me to analyse backend code for one the live websites that our company maintains. I have run into a problem. I can't quite figure what '#' is doing here in this code if(#($_SESSION['user'])){...}
I looked everywhere what this means and haven't found anything even remotely resembling this. I hope someone on this forum can help me out. Below is the entire code snippet.
if(#($_SESSION['user']))
{
$usrid=$_SESSION['user'];
$getprflimg=$db->singlerec("select img from register where
id='$usrid'");
$imgurlprl=$getprflimg['img'];
if(file_exists($url))
$imgurlprl=$siteurl."uploads/user_images/".$imgurlprl;
else
$imgurlprl=$siteurl."/uploads/user_images/no_image.png";
}
# before the variable is used to suppress the warning generated for that variable. This is also relevant to 'At' symbol before variable name in PHP: #$_POST.
This question already has answers here:
PHP: Variables in a Postgresql Query
(2 answers)
Closed 3 years ago.
I’m working on a project where I need to use postgresql to update info. I need to take
Martin’s chik ‘n’ chips
And make change it to
Martin\’s chik \’n\’ chips
How would I do this? I’ve looked at other posts, and found out to use substr() to create the new string and strpos() to find the ‘s, and even setting a new variable to keep the position of the previous ‘
Edit: thanks everyone, clearly didn’t do enough research!
If in PHP:
Check out str_replace(). e.g.
$text = "Martin’s chik ‘n’ chips";
$apostrophe = array("'","`","‘","’");
$newtext = str_replace($apostrophe,"\'",$text);
In this specific example, if you don't have any of the 'fancy' apostrophes, check out addslashes() as this will solve everything for you
This question already has answers here:
Finding #mentions in string
(6 answers)
Closed 5 years ago.
I have busting my balls on this one, and I have been trying numerous regex'es but just can't seem to get it right. (I am not that experienced in regex).
The following situation is going on, lets take this basic sentence for example;
I recently saw #john-doe riding a bike, did you noticed that too #foo-bar?
The trick here is to get only the #john-doe and #foo-bar parts from the string, preferably in an array:
$arr = [
'#john-doe',
'#foo-bar'
];
Could someone help me get on the right track?
You can use this regex (\#(?P<name>[a-zA-Z\-\_]+)) :
<?php
$matches = [];
$text = "I recently saw #john-doe riding a bike, did you noticed that too #foo-bar?";
preg_match_all ("(\#(?P<names>[a-zA-Z\-\_]+))" ,$text, $matches);
var_dump($matches['names']);
In this example, I used the ?P<names> to name the capture groups, it's easier to get it.
I've made a Regex101 for you, and a PHP sandbox for test
https://regex101.com/r/ZFWvCG/1
http://sandbox.onlinephpfunctions.com/code/1d04ce64a2a290994bf0effd7cf8f0039f20277b
This question already has answers here:
Replace preg_replace() to preg_replace_callback() [duplicate]
(2 answers)
Closed 5 years ago.
I've had a good look through all the previous topics and I don't understand enough PHP to use them to answer my questions so sorry in advance if this is really simple!
{
$content = preg_replace('/\$([\w]+)/e', '$0', $this->getTemplateStyle());
$custom_css = $this->getCustomCSS();
return $content.$custom_css;
}
And I need to replace preg_replace with preg_replace_callback. I know it's not a simple switch and that I need to add more to the code, but I don't know what to add. Thanks in advance for your help.
[SOLVED]
You seem to be trying to inject variables from the current scope into your string. I'll leave aside why this is a bad idea and assume there is no user input involved. First get the current scope:
$scope = get_defined_vars();
Next use the callback:
preg_replace_callback('/\$(\w+)/',function($m) use ($scope) {if( isset($scope[$m[1]])) return $scope[$m[1]]; else return $m[0];}, $this->getTemplateStyle());
Job done. – #Niet the Dark Absol
This question already has answers here:
How can I convert ereg expressions to preg in PHP?
(4 answers)
Closed 3 years ago.
i am using php 5.3.0 and i am use wamp server
function is like that
eregi("^[ \f\r\t\n]{0,}(SELECT){1}(.+)$",$this->ss_last_query)
eregi("^[ \f\r\t\n]{0,}(UPDATE|INSERT|DELETE){1}(.+)$",$this->ss_last_query)
Two options
Don't use the ereg* functions (use the PCRE suite instead)
Disable E_DEPRECATED error reporting. See error_reporting()
The best option is #1 as the entire POSIX Extended suite will be removed in a future version.
I can't comprehend how people are still using this. It's been marked for removal for years. Not to mention the pre-deprecated "These functions are inferior!" warning that was up for even longer.
Use the preg_match with the i modifier, which specifies that you want a case insensitive match with your regex.
So you want:
preg_match("/regexhere/i", $str);
error_reporting(E_ALL ^ E_DEPRECATED);
If you must use eregi, but...
preg_match("/^[ \f\r\t\n]{0,}(UPDATE|INSERT|DELETE){1}(.+)$/is", $this->ss_last_query)
should also work.