Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

How to append php string values into another string

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

How to append php string values into another string

Postby mikag2014 » Mon Aug 04, 2014 6:58 am

I have the following string $original="A0B0C0D0E0F0AB0AC0" which I want to be amended when a string such as $data="A4AB8" is put the final string to be $original="A4B0C0D0E0F0AB8AC0"
mikag2014
New php-forum User
New php-forum User
 
Posts: 1
Joined: Mon Aug 04, 2014 6:52 am

Re: How to append php string values into another string

Postby 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
landi
New php-forum User
New php-forum User
 
Posts: 236
Joined: Thu Mar 15, 2012 3:59 pm

Re: How to append php string values into another string

Postby us2rn4m2 » Thu Aug 07, 2014 7:46 am

Code: Select all
echo str_replace(array('A0', 'AB0'), array('A4', 'AB8'), "A0B0C0D0E0F0AB0AC0");
// A4B0C0D0E0F0AB8AC0
us2rn4m2
New php-forum User
New php-forum User
 
Posts: 17
Joined: Thu Aug 09, 2012 1:28 pm


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.