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
https://forums.phpfreaks.com/topic/42471-how-can-we-do-this/
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
https://forums.phpfreaks.com/topic/42471-how-can-we-do-this/#findComment-206075
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
https://forums.phpfreaks.com/topic/42471-how-can-we-do-this/#findComment-209398
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.