Jump to content

[SOLVED] What's wrong in this code - help please!


AHA7

Recommended Posts

Well, I have no idea what you are trying to do in these two instances. I have never seen any code like that:

 

${string2.$i}

${string2.$i}[0] (Corrected)

 

But, you also have a syntax error in the explode function - one too many quote marks.

 

If $i =0 then ${string2.$i} would be $string20, and ${string2.$i}[0] would be $string20[0].

What's the syntax error in the explode function. I want to split $string1 into strings bounded by double quote marks. the backslash is an escape char.

for($i=1; $i<=5; $i++)

{

${string2.$i} = explode("\"", $string1);

}

 

for($i=1; $i<=5; $i++)

{

echo ${relLink.$i}[0];

}

 

there is no "FOR" loop needed, to use the explode function.

The explode function outputs its data into an array.

Here is what i would do

 

<?php
$string1 = 'these\are\exploded\like\followed';  
$string_array = explode("\\", $string1); //NOTICE the "\\"???? The first \ (Backward slash) functions as an escape character for the second one
print_r($string_array);

echo "<br>First array numbered 0 contains:<b><font size=6>";
echo $string_array[0];
echo "</font></b><br>Second array numbered 1 contains:<b><font size=6>";
echo $string_array[1];
echo "</font></b><br>Third array numbered 2 contains:<b><font size=6>";
echo $string_array[2];
echo "</font></b><br><font size=6>etc....<font>";
?>

 

the print function just shows the content of an array.

i always look at the array in the source code of the output page.

you will have a much better overview.

 

or you can call the array's information by specifying the array number like this $arrayvariable[number]

hope this help

 

Greetz

 

Silverado

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.