textarea - How can I write specific lines from a text area form to a text file? PHP -
so want able paste text area , want write each particular line/word text file.
first name last name home (123) 345-6789 51 street name city, pr abc def the text file should write in format. first name last name!home (123) 345-6789!51 street name!city! pr !abc def! (note exclamation marks, spaces , coma). program should able read words line 1,2,3 regardless of how many words there are. line 4 in format 4 separate words. need output in particular format listed above. i'm confused about. if has solution appreciate it. i've tried many things , can't seem code work. i'm new if include as possible nice. thank you.
by making use of php's string functions.
<?php $str='first name last name home (123) 345-6789 51 street name city, pr abc def'; $new_str=""; foreach(explode(php_eol,$str) $val) { if(strpos($val,',')!==false) { $val=trim(str_replace(',','',$val)); //<--- space thing $val=explode(' ',$val); $new_str.=implode('!',$val)."!"; } else { $new_str.=trim($val)."!"; //<--- added here } } echo $new_str; output :
first name last name!home (123) 345-6789!51 street name!city!pr!abc!def!
Comments
Post a Comment