Forum Moderators: coopster

Message Too Old, No Replies

Correct output only if spaces between variables

But if there's a space, it messes up the output

         

Jeremy_H

8:28 pm on Jan 9, 2006 (gmt 0)

10+ Year Member



I'm having some trouble with my simple PHP script. For some reason, it's outputting different variables depending if there is a space between them or not.

Unfortunately, the space will mess up the script.

Any ideas what I'm doing wrong?

<?php
$sel1 = $_REQUEST['sel1'];
$folder = $_REQUEST['folder'];

$x=rand(52,71);

echo("/$folder/$sel1 $x 8.gif");
echo("<br>");
echo("/$folder/$sel1$x8.gif");
?>

Assuming $folder = "example" and $sel1 = "test" then, the first and second line outputs look like:

/example/test 56 8.gif
/example/test.gif

I need the output:

/example/test568.gif

What am I doing wrong here? Thanks so much for any help.

timster

9:02 pm on Jan 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this:

echo("/$folder/${sel1}${x}8.gif");

or this:

echo("/" . $folder . "/" . $sel1 . $x . "8.gif");

Use whatever you find easier to read.

Jeremy_H

9:32 pm on Jan 9, 2006 (gmt 0)

10+ Year Member



Thank you Timster, I used the concatenate method (the second one), and it works fine.

Thanks again