Jump to content

[SOLVED] Newbie - got a problem with ltrim


colinsp

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()

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.