php troubles!

Status
Not open for further replies.

rileypool

paper clique fiend
Mar 8, 2007
1,345
43
0
41
Tulsa, OK
rileypool.com
Okay, php is being a complete bitch to me right now and I for the life of me can't figure out why this code won't display like I think it should.

Here's the code that I can get to work exactly like I want it to.
PHP:
    echo '<input type="text" name="Avatar '.$int.'" class="" onclick="" value="<center><a href="'.$siteURL.'"><img src=""><br />'.$siteDescription.'</a></center>"><br /><br />';
And here's the code that I cannot get to display correctly.
PHP:
    echo '<input type="text" name="Avatar '.$int.'" class="" onclick="" value="<center><a href="'.$siteURL.'"><img src="'.$value.'"><br />'.$siteDescription.'</a></center>"><br /><br />';
If you guys are wondering how $value is being set, here's the entire block of code its being used it.
PHP:
foreach ($imgURL as $value) {
    echo '<img src="'.$value.'"><br />';
    echo 'Copy & Paste the Code Below to your Profile or Comment Box<br />';
    echo '<input type="text" name="Avatar '.$int.'" class="" onclick="" value="<center><a href="'.$siteURL.'"><img src=""><br />'.$siteDescription.'</a></center>"><br /><br />';
    $int++;
}
 


I just ran that line you say is not working correctly on my local server with some dud vars and it seems to output ok. This is the output I get in the textbox :

Code:
<center><a href="http://www.google.com"><img src="bla"><br />bladesc</a></center>
What were you expecting ?
 
That's weird. All I can say is that it works here.
This is the code I used to test :
PHP:
$int=0;
$siteURL = 'http://www.google.com';
$value = 'value';
$siteDescription = 'desc';
echo '<input type="text" name="Avatar '.$int.'" class="" onclick="" value="<center><a href="'.$siteURL.'"><img src="'.$value.'"><br />'.$siteDescription.'</a></center>"><br /><br />';
Which gives the following result in the textbox :

Code:
<center><a href="http://www.google.com"><img src="value"><br />desc</a></center>
What is the actual value of $value ? Does it have quotes or double quotes in it?
Please show us a sample output of exactly what goes wrong.
 
What is the actual value of $value ? Does it have quotes or double quotes in it?
Please show us a sample output of exactly what goes wrong.
This was my idea, too. If it's stopping after $value then it must contain some unescaped characters. A 'View Source' of the output when it goes wrong could help to solve this.
 
Here's a sample output of the HTML source from the output file.

HTML:
<img src="http://i167.photobucket.com/albums/u138/mycomments_2007/Avatars/avatar2-seekcodes688.gif"><br />Copy & Paste the Code Below to your Profile or Comment Box<br /><input type="text" name="Avatar 0" class="" onclick="" value="<center><a href="http://get-commented.topmsrs.com"><img src="http://i167.photobucket.com/albums/u138/mycomments_2007/Avatars/avatar2-seekcodes688.gif"><br />get-COMMENTED!  For all your MySpace Commenting needs!</a></center>"><br /><br />
 
Here's the entire script I'm using. Can anybody please help me troubleshoot this issue I'm having?

PHP:
<?php
$file = fopen("http://get-commented.topmsrs.com/test/urls.txt", "r") or exit("Unable to open file!");

$siteURL = "http://get-commented.topmsrs.com";
$siteDescription = "get-COMMENTED!  For all your MySpace Commenting needs!";
$imgURL = array();
$i = 0;
$int = 0;

while(!feof($file)) {
    $imgURL[$i] = fgets($file);
    $i++;
}
fclose($file);

echo '<center>';
foreach ($imgURL as $value) {
    echo '<img src="'.$value.'"><br />';
    echo 'Copy & Paste the Code Below to your Profile or Comment Box<br />';
    echo '<input type="text" name="Avatar '.$int.'" class="" onclick="" value="<center><a href="'.$siteURL.'"><img src="'.$value.'"><br />'.$siteDescription.'</a></center>"><br /><br />';
    $int++;
}
echo '</center>';
?>
 
Instead, I used this line of code and it made everything much simpler to read and understand. Plus it works perfectly to boot!

PHP:
    echo '<textarea name="Avatar '.$int.'" cols="80" rows="3"><center><a href="'.$siteURL.'"><img src="'.$value.'"><br />'.$siteDescription.'</a></center></textarea><br /><br />';
 
Status
Not open for further replies.