This question already has answers here:
How can I convert ereg expressions to preg in PHP?
(4 answers)
Closed 9 years ago.
My id is a5efa5.
Code below replacing deprecated[?] [^a-z0-9] is not working. a5efa5 in an id in my database table.
//Connect to the database through our include
include_once "database.php";
// Get the member id from the URL variable
$id = $_REQUEST['id'];
$id = ereg_replace("[^a-z0-9]", "", $id); // filter everything but numbers for security
if (!$id) {
echo "Missing Data to Run";
exit();
}
Help me friends, where did I make a mistake...
It could be because ereg_replace is deprecated. Below is what is stated on the php.net website
This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.
If you are using a version or PHP greater than 5.3.0 then it will not work.
Use preg_replace
$id = preg_replace('#[^a-z0-9]+#', '', $id);
Related
This question already has answers here:
PHP 7.2 Function create_function() is deprecated
(6 answers)
Closed 1 year ago.
I have a function which im not entirely sure how to convert it to get working in newest php
$eventSponsor = array_map(create_function('$o', 'return $o["id"];'), $event->sponsors);
which method should i use in newest php version ?
yeah i was searching and i found this method called anonymous function so the code be like
$awe function ($o) {
return $o["id"];
};
$eventSponsor = array_map($awe,$event->sponsors); ```
This question already has answers here:
ereg/eregi replacement for PHP 5.3 [duplicate]
(4 answers)
How to replace eregi()
(2 answers)
How can I convert ereg expressions to preg in PHP?
(4 answers)
Alternative to eregi() in php [duplicate]
(1 answer)
How to change PHP's eregi to preg_match [duplicate]
(2 answers)
Closed 4 years ago.
The web hosting service provider upgraded to PHP 7.1 and it broke the contact form of the page. I've narrowed it down to this piece of code:
function check_email($mail)
{
$email_host = explode("#", $mail);
$email_host = $email_host['1'];
$email_resolved = gethostbyname($email_host);
if ($email_resolved != $email_host && #eregi("^[0-9a-z]([-_.~]?[0-9a-z])*#[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$",$mail))
$valid = 1; return $valid;
}
I've found that the eregi function is no longer supported in PHP 7.1 but I dont know how and with what i should replace it.
Have a look at the documentation of eregi function in php.net:
Warning
This function was DEPRECATED in PHP 5.3.0, and REMOVED in PHP 7.0.0.
Alternatives to this function include:
preg_match() (with the i (PCRE_CASELESS) modifier)
You should always have a look there when it comes do deprecated functions.
For validating email addresses you could also use filter_var now:
if (filter_var('test#example.com', FILTER_VALIDATE_EMAIL)) {
echo "Email valid.";
}
This question already has answers here:
Why shouldn't I use mysql_* functions in PHP?
(14 answers)
Closed 5 years ago.
I'm working on a login form and am using some code from a tutorial.
Now I don't remember what the mysql_prep was for and whether it's deprecated, since it's not mysqli... I couldn't really make sense of what I googled.
Is it ok to use this or should I use something else or not use it all together?
It looks like this (variables used to update SQL table):
$username = mysql_prep($_POST["username"]);
$password = mysql_prep($_POST["password"]);
$hashed_password = password_hash($_POST["password"], PASSWORD_DEFAULT);
mysql_prep must be some user defined function. It does not exist in the php docs.
http://php.net/manual-lookup.php?pattern=mysql_prep&scope=quickref
Look inside this function in your own code and if it has any references to mysql_ functions then consider it deprecated. All mysql_ functions are deprecated as of PHP 5.5 and are removed in PHP 7.
Use mysqli_ functions or PDO instead.
This question already has answers here:
Alternative for deprecated PHP function: eregi_replace [duplicate]
(2 answers)
Closed 8 years ago.
I'm trying to fix a picture upload.
But I have some troubles with the check if the file is a picture.
Before I used eregi_replace but that function is deprecated and now I'm wondering is there possible to use preg_match and check in an array for a match or how should I do this?
$name = "Picture.jpg";
$picture = array("/^JPG/", "/^PNG/", "/^GIF/", "/^gif/", "/^png/", "/^jpg/", "/^JPEG/", "/^jpeg/");
$something = preg_match($picture, $name, $matches, PREG_OFFSET_CAPTURE, 3);
print_r($something);
Like that or something? I dont have a clue, hope you can help me!
Like below:
$name = "Picture.jpg";
if (preg_match('/\.(jpe?g|png|gif)$/i', $name, $matches)) {
//...
}
But note this only check the filename, if you want to check it's a real image, you should validate the actual mime-type.
This question already has answers here:
MySQLi equivalent of mysql_result()?
(12 answers)
Closed 10 months ago.
I am converting my project from mysql to mysqli and my problem is that mysqli_result() does not work with my old code. My old code is: mysql_result($res,0,0);
When I try adding mysqli_result() with my old code it will not work.
Is there another way that'll work with my old parameters?
mysqli_result() will not work with your old parameters so you need to create a new function, Here is the code for a function that'll work with your old prameters:
function mysqli_result($res, $row, $field=0) {
$res->data_seek($row);
$datarow = $res->fetch_array();
return $datarow[$field];
}