FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » variable path lose slashs when used in an alert
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
variable path lose slashs when used in an alert [message #177526] Fri, 06 April 2012 15:05 Go to next message
anver is currently offline  anver
Messages: 5
Registered: November 2010
Karma: 0
Junior Member
variable $temp is a path
C:\www\site\test\folder\img.jpg

if I write
echo $temp;
ok I have all the path
---------

but if I use same variable in an alert I haven't more the correct path;
haven't the \ slashs

echo"<script type='text/javascript'>";
echo "alert('$temp')";
echo "</script>";

I tested also string but is equal
$temp=(string)$temp;


is there a solution?
Re: variable path lose slashs when used in an alert [message #177529 is a reply to message #177526] Fri, 06 April 2012 15:37 Go to previous messageGo to next message
J.O. Aho is currently offline  J.O. Aho
Messages: 194
Registered: September 2010
Karma: 0
Senior Member
anver wrote:
> variable $temp is a path
> C:\www\site\test\folder\img.jpg
>
> if I write
> echo $temp;
> ok I have all the path
> ---------
>
> but if I use same variable in an alert I haven't more the correct path;
> haven't the \ slashs
>
> echo"<script type='text/javascript'>";
> echo "alert('$temp')";
> echo "</script>";
>
> I tested also string but is equal
> $temp=(string)$temp;
>
>
> is there a solution?

In most systems and scripting languages, the back slash '\' is an "escape"
sign, for example \n is treated as new line, \t as tab, and this is what your
javascript is doing and for a backslash to work, you need to use a double
backslash '\\'.



--

//Aho
Re: variable path lose slashs when used in an alert [message #177534 is a reply to message #177526] Sat, 07 April 2012 11:30 Go to previous message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
Am 06.04.2012 17:05, schrieb anver:
> variable $temp is a path
> C:\www\site\test\folder\img.jpg
>
> if I write
> echo $temp;
> ok I have all the path
> ---------
>
> but if I use same variable in an alert I haven't more the correct path;
> haven't the \ slashs
>
> echo"<script type='text/javascript'>";
> echo "alert('$temp')";
> echo "</script>";
>
> I tested also string but is equal
> $temp=(string)$temp;
>
>
> is there a solution?

In addition to what //Aho said, you could use a normal forward slash as path
separator, see
http://us2.php.net/manual/en/ref.filesystem.php#73954

/Str.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: variable path lose slashs when used in an alert
Next Topic: PHP5 DOM extension - using firstChild
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 08:21:53 GMT 2024

Total time taken to generate the page: 0.03716 seconds