i have a long list of numbers like this 36346346 436346 444444 44 666666666666865 4564 . . . and at the beginning and end of each entry i want to append some characters . how do to this with php? thanks
Is your list in an array? If so, you can use a foreach statement to do this. E.g. $array = array(1234,12345,123456,1234567); foreach($array as $value) { $string .= $value . "SOMECHARACTERS"; } echo $string; PHP:
lol if I had the time to add a comma at the end of each entry why would I need this code in the first place? anyone else got ideas?
You can remove <br /> its just to show how it would look <?php $str = " 36346346 436346 444444 44 666666666666865 4564"; $text = str_replace("\n", "<br />\n^^^^^", $str); // ^^^^^ = your characters or are they different on each line ? echo $text; ?> PHP: Example out put: ^^^^^36346346 ^^^^^436346 ^^^^^444444 ^^^^^44 ^^^^^666666666666865 ^^^^^4564 Code (markup):
So what is your list then? A text file of numbers one after the other with a linebreak separating them? $filename = "c:\\folder\\number.txt"; $file = fopen($filename, "w+"); if(!$file) return false; $data = file_get_contents($filename); fclose($file); $data = explode("\n", $data); foreach($data as $value) { $string .= $value . "SOMECHARACTERS"; } echo $string; PHP: You may have to try other characters for the explode function depending on the newline value. <br />, \nr, \r or w/e else represents a newline.