How to append php string values into another string

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

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

Re: How to append php string values into another string

Post by landi » Mon Aug 04, 2014 9:04 am

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

Code: Select all

$original="A0B0C0D0E0F0AB0AC0";
$data="A4AB8";
$original=substr($data,0,2) . substr($original, 2, 11) . substr($data, 2, 3) . substr($original, -3, 3);
//$original="A4B0C0D0E0F0AB8AC0"
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

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

Re: How to append php string values into another string

Post by us2rn4m2 » Thu Aug 07, 2014 7:46 am

Code: Select all

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

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest