Jump to content

How can we do this?


phpcod3r

Recommended Posts

Imagine i have a text file with the following contents:

Helloworld1*Helloworld2

Word1*Word2

 

And now i have a HTML form generated through a PHP file with a multi-line edit box, and i have put the following text in it:

 

Some text here Helloworld1 and some text here Word1 comes.

 

Now when someone presses the submit button, the above text in the multi line box changes to:

 

Some text here Helloworld2 and some text here Word2 comes.

( by gathering data from the text file )

 

Thats the best i could explain, how can we do that?

Link to comment
Share on other sites

$file_array="/path/to/your/file"; /*this will read the file into an array line by line. line 1 would be accessed as $file_array[0] */

foreach($file_array as $value){ // loop through each line and explode on the * creating a new array

$new_array=explode('*',$value); // set $new_array variable.

}

// access the $new_array variable here and do something with it.

 

That is not complete, but it's the best I can do with what you provided.

 

read up on the file function and the explode function in the manual

 

http://us2.php.net/manual/en/function.file.php

http://us2.php.net/manual/en/function.explode.php

Link to comment
Share on other sites

I am having problems understanding this, why theres a $value? ..... i need to place this code in a PHP file and edit the file path to the file having the same format as i've mentioned in the thread and the script will do the replacing while going through the lines and put the final replaced text in $new_array, am i right.... if not then please explain

 

thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.