Jump to content

strip first letter


jeff5656

Recommended Posts

Ok I figured it out.  But instead of being cryptic about it, I will post the solution here so that others can see it in the future:

while ($row=mysql_fetch_assoc($result)){
$string = $row['cpt'];
if ($string[0] == 'P' ){
	$new_cpt = substr($row['cpt'], 1); 
}
else {$new_cpt =$row['cpt'];}
echo $row['cpt']." and new is ".$new_cpt."<br>";
}

Link to comment
https://forums.phpfreaks.com/topic/243515-strip-first-letter/#findComment-1250423
Share on other sites

I'm sorry,

 

if(substr($string, 0, 1)=="P"){$string = substring($string, 1, strlen($string));}

 

This should do it

Just a small comment: In the way you're using substr() there (you also put substring() instead of substr()), the third parameter is superfluous. In fact, you'd be trying to take one extract character that doesn't exist from the string.

 

$string = substr($string, 1);

 

Would suffice.

Link to comment
https://forums.phpfreaks.com/topic/243515-strip-first-letter/#findComment-1250432
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.