split() deprecated. How to convert? [duplicate] - php

This question already has answers here:
Deprecated: Function split() is deprecated. How to rewrite this statement?
(4 answers)
Closed 9 years ago.
I have a piece of code that's using the split() function. PHP is complaining that the function is deprecated. How can this be converted to a non deprecated split?
if(!empty($vis_settings['url']['urls'])){
$split_urls=split("[\n ]+",(string)$vis_settings['url']['urls']);

You can use preg_split.
$split_urls = preg_split("/[\n ]+/",(string) $vis_settings['url']['urls']);

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);

PHP 5.1 to PHP 7.1 broke contact form [duplicate]

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.";
}

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'])

Eregi_replace to preg_replace conversion needed [duplicate]

This question already has answers here:
How can I convert ereg expressions to preg in PHP?
(4 answers)
Closed 3 years ago.
i need to convert this in order to use preg_replace because eregi_replace is deprecated
$n=eregi_replace(")+.+","",$value);
$id=eregi_replace(".+)","<a hсref='http://www.company.com/product.php?id=".$n."'>",$value);
$newstr.="".$id."</a><br>";
//..... must be converted
its very unclear to me how that would look in preg_replace
$gexpieces = explode(")", $value);
$n=$gexpieces[0];//n is product id
unset($gexpieces[0]);
$prodname = implode($gexpieces);
$newstr.="<a href='http://www.company.com/product.php?id=".$n."'>".$prodname."</a><br/><br/>";
nevermind, done it myself.

Categories