How to append php string values into another string

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
php-forum Active User
php-forum Active User
Posts: 388
Joined: Thu Mar 15, 2012 3:59 pm

Mon Aug 04, 2014 9:04 am

I think you could explain a bit better, but perhaps this will help:

Code: Select all

$original=substr($data,0,2) . substr($original, 2, 11) . substr($data, 2, 3) . substr($original, -3, 3);
The substr(s, i, l) function returns the sub string of s that starts at character number i (zero = first character), and is l characters long. Note that you can use negative numbers to start counting from the right e.g. -3 which means starting at the character 3 from the right. (Forgive me if I've miscounted any of the strings!)

If however you meant something else, please expand your question.
- A

New php-forum User
New php-forum User
Posts: 17
Joined: Thu Aug 09, 2012 1:28 pm

Thu Aug 07, 2014 7:46 am

Code: Select all

echo str_replace(array('A0', 'AB0'), array('A4', 'AB8'), "A0B0C0D0E0F0AB0AC0"); 
// A4B0C0D0E0F0AB8AC0

Post Reply