Forum Moderators: coopster

Message Too Old, No Replies

conditional relpace line

depending on first 5 chars

         

WebNeeds

5:01 pm on Aug 13, 2004 (gmt 0)

10+ Year Member



$string = "abcde";
$file = file_get_contents($myfile);
if ($string_is_the_first_five_chars_of_a_line){
replace that line with $string.$string2;
}else{
add $string.$string2 to the end
}

WhosAWhata

5:52 pm on Aug 13, 2004 (gmt 0)

10+ Year Member



look at
explode()
foreach()
ereg()
ereg_replace()

WebNeeds

5:54 pm on Aug 13, 2004 (gmt 0)

10+ Year Member



i'm sorry but i don't really know PHP, could someone give me a boost?

jatar_k

9:56 pm on Aug 13, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



well, since file_get_contents returns the whole file as one big string what about substr

if ($string == substr($file0,5)) {
etc ...

but are you trying to read it line by line or just as a single string?