[ale] [OT] PHP Question

Nathan J. Underwood lists at cybertechcafe.net
Tue Feb 17 15:40:30 EST 2004


Thank You!!!!!


J.M. Taylor wrote:

> $string = "johndoe";
> $newstring = substr($string,0,3);
> 
> (take the substring of $string starting at position 0, give me 3 
> characters)
> 
> http://us2.php.net/manual/en/function.substr.php
> 
> hth
> jenn
> 
> On Tue, 17 Feb 2004, Nathan J. Underwood wrote:
> 
> 
>>Is there a way to say "Just give me the first n characters of a string" 
>>in PHP?  For example, if the string was "johndoe", and I just wanted the 
>>first 3 characters, or "joh"?  I think I could do it with some kind of 
>>regex, but I can't seem to come up with one that works.  It will be used 
>>in a MySQL query when it's done, like the following:
>>
>>$string = "johndoe";
>>$newstring = justgivemetheleft3($string);
>>
>>$query = "SELECT * from table where name like "$newstring%"
>>
>>I can't say give me everything that matches johndoe, because some of 
>>them are john doe, some are john_doe, some are john, etc.  But, the 
>>first 3 will always be right.
>>_______________________________________________
>>Ale mailing list
>>Ale at ale.org
>>http://www.ale.org/mailman/listinfo/ale
>>
>>
> 
> 



More information about the Ale mailing list