string split ?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Mon Mar 31, 2014 6:17 am

string split ?

Postby fraizoor » Mon Mar 31, 2014 6:25 am

hi all
i'm new to this lovly forum im a noob in php and i need soem help please

i have this code

Code: Select all

$file = 'data.log';
$handle = fopen($file, 'w') or die('Cannot open file: '.$file);
$data = "";

foreach ($_POST as $key => $value)
  $data = $data.$value."\n";
fwrite($handle, $data);


this code is for receving a HTTP post reqest and write its content to a file called "data.log"
it is working fine but i want to make a change in it so it recives the request and split it for 2 pices . the splitter is $ mark
the string before the $ mark is the file name and after the $ mark is the data

EX of the request:


and i must see in my file manager

inside it: hiimatextfile

the $ sign must not be mentioned from both the name and the data

any 1 can help?

New php-forum User
New php-forum User
Posts: 31
Joined: Fri Apr 06, 2012 9:54 pm

Re: string split ?

Postby raphael75 » Mon Mar 31, 2014 10:37 am

I think you are looking for the explode() function:

php-forum Fan User
php-forum Fan User
Posts: 936
Joined: Mon Oct 01, 2012 12:32 pm

Re: string split ?

Postby seandisanti » Wed Apr 02, 2014 1:35 am

as raphael75 suggests, explode is the way to go if you're storing both in the same value, but you're already sending an associative array with $_POST, why not have it so that the filename is the key and the data is the value?

Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 3 guests