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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.