phpcod3r Posted March 13, 2007 Share Posted March 13, 2007 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? Quote Link to comment Share on other sites More sharing options...
bwochinski Posted March 13, 2007 Share Posted March 13, 2007 Use explode() to separate the parts of the string. Then you can use them wherever you like. Quote Link to comment Share on other sites More sharing options...
phpcod3r Posted March 13, 2007 Author Share Posted March 13, 2007 I have just started with PHP so i have no idea what you are talking about, can you show me an example? Quote Link to comment Share on other sites More sharing options...
only one Posted March 13, 2007 Share Posted March 13, 2007 i used to have a code that did that sort of thing only for users online.... ill see if i can find it Quote Link to comment Share on other sites More sharing options...
only one Posted March 13, 2007 Share Posted March 13, 2007 soz cant find it ... http://pixel2life.com check that out, your bound to get what your looking for Quote Link to comment Share on other sites More sharing options...
chronister Posted March 13, 2007 Share Posted March 13, 2007 $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 Quote Link to comment Share on other sites More sharing options...
phpcod3r Posted March 17, 2007 Author Share Posted March 17, 2007 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.