splitting a variable
Moderator: General Moderators
- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
splitting a variable
if i get a output of
some text here :: more text here
and it is 1 valriable is there any way to split it up kinda so i can control the 1st half as a variable and the 2nd half as a seperate variable? i know its kinda a vauge question but im not sure how i can elaborate much more but if u need me to i will try
some text here :: more text here
and it is 1 valriable is there any way to split it up kinda so i can control the 1st half as a variable and the 2nd half as a seperate variable? i know its kinda a vauge question but im not sure how i can elaborate much more but if u need me to i will try
-
Robert Plank
- Forum Contributor
- Posts: 110
- Joined: Sun Dec 26, 2004 9:04 pm
- Contact:
Code: Select all
$string = "some text here :: more text here";
list($first, $second) = explode(" :: ", $string);
echo "first thing: $first, second thing: $second";- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
problems! the string is a value in a array so i did
but it leaves the $name4 and $message4 as just nothing. is this because im turing a array value into a variable? can't i do that?
Code: Select all
<?php
$array[$i] = $newstring2;
list($name4, $message4) = explode(" :: ", $newstring2);
fwrite($opened, "$name4 :: $message4");
?>- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
What is defined as?
Code: Select all
$i- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
full code looks like this -
Code: Select all
<?php
$file = "comments/$file";//get the file
$linenum = $_REQUEST['linenum'];//get the line number you want to edit
$newstring = $editedcom;//get the text you want to put in the line
$array = file($file);
$array[$linenum - 1] = $newstring;
$numberlines = count($array);
$opened = fopen ($file, "w+");
for ($i = 0; $i<$numberlines; $i++) {
$array[$i] = $newstring2;
list($name4, $message4) = explode(" :: ", $newstring2);
fwrite($opened, "$name4 :: $message4");
}
fclose($opened);
?>- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
Code: Select all
<?php
$txt = "comments/$file";
$opentxt = fopen($txt, 'r');
$i = 1;
while (!feof($opentxt)) {
$readtxt = fgetss($opentxt, 5000);
?>
<form action="admin.php?id=editcomments2&file=<? print $file; ?>" method="post">
<input type="text" name="editedcom" value="<? print $readtxt; ?>">
<input type="hidden" name="linenum" value="<? print $i; $i++; ?>">
<input type="submit" name="submit" value="Edit Text">
</form>
<br>
<?
}
?>
<?
fclose($opentxt);
?>Code: Select all
<?php
$file = "comments/$file";//get the file
$linenum = $_REQUEST['linenum'];//get the line number you want to edit
$newstring = $editedcom;//get the text you want to put in the line
$array = file($file);
$array[$linenum - 1] = $newstring;
$numberlines = count($array);
$opened = fopen ($file, "w+");
for ($i = 0; $i<$numberlines; $i++) {
$array[$i] = $newstring2;
list($name4, $message4) = explode(" :: ", $newstring2);
fwrite($opened, "$name4 :: $message4");
}
fclose($opened);
?>-
Robert Plank
- Forum Contributor
- Posts: 110
- Joined: Sun Dec 26, 2004 9:04 pm
- Contact:
Why isn't line 5
instead?
Code: Select all
$newstring = $_REQUEST['editedcom'];- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
cause i got lazy and it really dosnt make much of a diffrence but it would be more stable so i just changed it but thats not going to solve my problem...
also just so whoever looks at my code knows i am completly new to arrays and i cant quite grasp the for loop command so bear with me please. and also when i go to edit the line it not only deletes that line it changes EVERY line in the file to just :: ??? but when i just use
it works perfectly? AHHHHHHHH
also just so whoever looks at my code knows i am completly new to arrays and i cant quite grasp the for loop command so bear with me please. and also when i go to edit the line it not only deletes that line it changes EVERY line in the file to just :: ??? but when i just use
Code: Select all
<?php
fwrite($opened, $array[$i])
?>- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
how would i go about not doing that? i was thinking of doing somtin like
but that wouldnt work because of the 2 equal signs rite?
Code: Select all
<?php
$array[$linenum - 1] = list($name4, $message4) = explode(" :: ", $newstring2)
?>- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
$newstring2 =& $arrayї$i];