Jump to content

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


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}

${relLink.$i}[0]

 

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

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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.