Jump to content

Recommended Posts

I have a little problem. I have searched the php manual and a couple of books without success. I am trying to get my head round the ltrim command.

 

Say I have a variable and it contains 12345-ABCDEF and I just want to assign the letters to another variable the code I have tried is

 

$one ="12345-ABCDEF";
$two = ltrim($one, "-");
echo $two"\ n";

 

I still get 12345-ABCDEF instead of ABCDEF so it has to be me not understanding how this function works properly. Is this the proper way to do this or is there a better way?

 

TIA for any suggestions.

 

--

Colin

Link to comment
https://forums.phpfreaks.com/topic/147022-solved-newbie-got-a-problem-with-ltrim/
Share on other sites

All ltrim does is remove whitespace from the left side of the string.

What you need is to use substr() to get a substring or use preg_match() to extract the non numeric part or break up the string using the hyphen i.e. explode()

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.