This is a discussion on "Read First 3 characters and last 4 characters of string" within the PHP Forum section. This forum, and the thread "Read First 3 characters and last 4 characters of string are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Read First 3 characters and last 4 characters of string
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
||||
|
Read First 3 characters and last 4 characters of string
Ok, I am working on something and I need to take a variable (with string information) and look at the first 3 characters and the last 4 characters. I have been baffled as how to do this but I know it can be done (Because everything can be done in PHP!) haha.
Last Blog Entry: Happy Holidays - A Non Offensive way to say Merry Christmas? WRONG! (Dec 11th, 2007)
|
|
|
|
|||
|
Re: Read First 3 characters and last 4 characters of string
<?php
$string = "Qwertyuiop"; $toptail = preg_replace('/(...).*(....)/','$1$2',$string); print $toptail; ?> |
|
|||
|
Re: Read First 3 characters and last 4 characters of string
You could also have a look at the strlen() and substr() functions.
substr(string,start,length) start = - positive number to start from beginning of the string, negative number to start from end of string. - The size of the number means from where the count should start. (3 means start from third character from the beginning of string) length = how many characters from 'start' P.s.: I didn't test the code. Last edited by skuliaxe; Apr 4th, 2008 at 00:10. |
![]() |
| Tags |
| first, last, strings |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Converting UTF-8 characters to ISO | darkling235 | JavaScript Forum | 2 | Mar 23rd, 2008 22:40 |
| Change a string of characters with aonether in a HTML file | r3ticul | JavaScript Forum | 4 | Jan 21st, 2008 09:28 |
| Detecting characters between < and > ? | Kerosene | JavaScript Forum | 5 | Jan 16th, 2008 16:32 |
| Japanese characters | Sheela | Starting Out | 11 | May 12th, 2007 22:20 |
| validate non-ASCII characters | brio | PHP Forum | 1 | Feb 7th, 2007 10:08 |