Re: substr() problems

From: Date: Fri, 06 Feb 2004 22:51:21 +0000
Subject: Re: substr() problems
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-32835@lists.php.net to get a copy of this message
I don't see anything initially wrong with this statement, but you might try a variation and see what you get. First: condense this: $DB_sub_ref = substr($DB_temp_ref , 0, 1); $DB_sub_ref .= substr($DB_temp_ref , 1, 1); to this: $DB_sub_ref = substr($DB_temp_ref , 0, 2); Your code will run slightly faster... Second change the third line there to: $DB_sub_ref .= substr($DB_temp_ref , -1); That should do the same thing, grab the last character in that string. Try that and see what you get. Jeremy "James Meers" <jambo@venda.com> wrote in message news:CB8DA9AF0B85D948B7A3F404B49C02A76741E3@vendac01.uk.venda... > Hi all, > > I am trying to use substr() negative start, but I get nothing returned - if i do a positive start then i do get something back, below is my code and a line of what i get returned: > > $DB_ref = "210020007"; > > $DB_temp_ref = $DB_ref; > > $DB_sub_ref = substr($DB_temp_ref , 0, 1); > $DB_sub_ref .= substr($DB_temp_ref , 1, 1); > $DB_sub_ref .= substr($DB_temp_ref , -1, 1); > > echo "$DB_sub_ref - $DB_ref"; > > RESULT: > > "21 - 210020007" > > note: 210020007 is an example this is actually within a while statement using mysql_fetch_array from a SQL query - all results are not returning the negative string. > > Can anyone help? > > > PHP Version 4.3.3 > > > Apache/2.0.47 (Fedora) > > Many thanks in advance, > > James. > > > > > > > > >

« previous php.db (#32835) next »