homepage Welcome to WebmasterWorld Guest from 54.237.213.31
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
split Deprecated
ModernMerlin



 
Msg#: 4459233 posted 11:03 pm on May 29, 2012 (gmt 0)

I was given code that is for password protecting a site. When I try to change the password the site tells me the function split is deprecated. So I looked it up and was told to use preg_split instead.

When I try to use that I get an error message:

Warning: preg_split() [function.preg-split]: Empty regular expression in /home/mmoprotools/www/secure/globalFns.php on line 5

Warning: Cannot modify header information - headers already sent by (output started at /home/mmoprotools/www/secure/globalFns.php:5) in /home/mmoprotools/www/secure/admin/resetPwd.php on line 33

The Code for the first error is :
require_once(dirname(__FILE__) . "/menus.php");

function getFirstName($fullName) {
$parts = split(" ", $fullName);
return $parts[0];
}


Any suggestions would be greatly appreciated! Thanks!

 

ModernMerlin



 
Msg#: 4459233 posted 2:37 am on May 30, 2012 (gmt 0)

I no longer need an answer to this. I'm using something else now.

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4459233 posted 6:58 am on May 30, 2012 (gmt 0)

The sample code you supplied didn't contain
preg_split
rlange



 
Msg#: 4459233 posted 2:33 pm on May 30, 2012 (gmt 0)

I suspect the issue was that you simply changed
split to preg_split without also changing the first argument. The relevant line should be:

$parts = preg_split("/ /", $fullName);

Although using
explode [us3.php.net] may be better in this case.

--
Ryan

rocknbil

WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4459233 posted 4:19 pm on May 30, 2012 (gmt 0)

Agreed, any single character is not really a pattern, any of the 'reg functions are meant to match on patterns. :-)

SteveWh

5+ Year Member



 
Msg#: 4459233 posted 6:16 pm on May 30, 2012 (gmt 0)

I know this might seem obvious, but it seems to be frequently misunderstood.

When you get a PHP warning that says "____ is deprecated. Use ____ instead", it doesn't mean that you should just change the name of the function.

It means that you should go to the PHP manual ( [php.net...] ), look up the function you were using, look up the new function, and change your code so it uses the new function properly, using the rules and requirements for its use.

The two functions are often very similar, but they won't be exactly the same.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved