explode array for fread fwrite uchhhh

 

Post Count: 20
Location: Newport, Wales
Post Title: explode array for fread fwrite uchhhh
 
Okayy
So I have a text area, the value of which is determined by $_POST the value would be something like:
Text Code:
++test1
++test2
++test3
okay so my code is:
PHP Code:
<?php
$array 
explode('++'$_POST['feats']);
echo 
$_POST['feats'];
for(
$i 0$i count($array); $i++){
    
fwrite($fh"++ " $array[$i]);
}
?>
so id expect it to write
Text Code:
++ test1
++ test2
++ test3
but instead there is an extra ++ ie:
Text Code:
++ ++ test1
++ test2
++ test3
any ideas?
 
Posted On
27th Feb 10 @ 11:12:pm
User IP: Logged
Jesus
I Have Godly Powahz

Post Count: 462
Location: London, UK
Post Title: RE: explode array for fread fwrite uchhhh
 
str_replace('++ ', '', $array[$i]);

should fix your problem.



v4yyps.png
Posted On
27th Feb 10 @ 11:47:pm
User IP: Logged

Post Count: 20
Location: Newport, Wales
Post Title:
 
edit: oh hang on, where?
 
Posted On
27th Feb 10 @ 11:26:pm
Post Has Been Edited 1 Times. Last Edited By OMGitsRhys. User IP: Logged
Linky
CMS God

Post Count: 402
Location: UK
Post Title: RE: explode array for fread fwrite uchhhh
 
PHP Code:
<?php
$array 
explode('++'$_POST['feats']);
echo 
$_POST['feats'];
for(
$i 0$i count($array); $i++){
    
$array[$i] = str_replace('++ '''$array[$i]);
    
fwrite($fh"++ " $array[$i]);
}
?>



"Shit happens, and then you recode. And I happen to recode quite a lot..."
Linky.png
Posted On
27th Feb 10 @ 11:57:pm
User IP: Logged

Post Count: 20
Location: Newport, Wales
Post Title:
 
still get the extra "++ "
 
Posted On
27th Feb 10 @ 11:08:pm
User IP: Logged

Post Count: 20
Location: Newport, Wales
Post Title:
 
i didnt know whether i shoudlve used foreach?
 
Posted On
28th Feb 10 @ 12:00:am
User IP: Logged
Linky
CMS God

Post Count: 402
Location: UK
Post Title: RE: explode array for fread fwrite uchhhh
 
PHP Code:
<?php
$var 
= <<<TXT
++test1
++test2
++test3
TXT;

$array explode('++'$var);
echo 
$var;
foreach(
$array as $value){
    
#fwrite($fh, "++ ".$value);
    
echo "++ ".$value.'';
}
?>

output wrote
++test1 ++test2 ++test3++
++ test1
++ test2
++ test3

there u go :)



"Shit happens, and then you recode. And I happen to recode quite a lot..."
Linky.png
Posted On
28th Feb 10 @ 12:31:am
User IP: Logged

Post Count: 20
Location: Newport, Wales
Post Title:
 
lmfao look at the first line
theres still an extra ++ at the end

ive worked out the problem
i just dont know how to fix it
look back to when it was just "for"

$i = 0
$i++
which means its starting with $i = 1

i thinks :S
 
Posted On
28th Feb 10 @ 12:55:am
User IP: Logged
Linky
CMS God

Post Count: 402
Location: UK
Post Title: RE: explode array for fread fwrite uchhhh
 
lmao, here :D

PHP Code:
<?php
$var 
= <<<TXT
++test1
++test2
++test3
TXT;

$array explode('++'$var);
echo 
$var;
foreach(
$array as $value){
    if(empty(
$value)) continue;
    
#fwrite($fh, "++ ".$value);
    
echo "++ ".$value.'';
}
?>



"Shit happens, and then you recode. And I happen to recode quite a lot..."
Linky.png
Posted On
28th Feb 10 @ 12:12:am
Post Has Been Edited 1 Times. Last Edited By Linky. User IP: Logged

Post Count: 20
Location: Newport, Wales
Post Title:
 
woo :')
got there in the end
ta :)

Am working on a change log appender :')
 
Posted On
28th Feb 10 @ 12:54:am
User IP: Logged