Jump to content


Photo

Help with echo


  • Please log in to reply
7 replies to this topic

#1 switchdoc

switchdoc
  • Members
  • PipPip
  • Member
  • 22 posts
  • LocationColorado

Posted 21 August 2006 - 02:17 AM

Hello all!

Hoping you can help me with what is probably a simple issue but it has me stymied.

I am working with google maps and ajax and I have to take a fairly complex bit of info and stuff it into one variable. Here it is:

echo "var point = new GLatLng(" . $location . ");";
echo "var marker = createMarker(point,\"$name\",'<div id=\"infowindow\" style=\"white-space: nowrap;\">"
  . addslashes($row['name'])
  . $spacer
  . addslashes($row['address'])
  . $spacer
  . addslashes($row['city'])
  . $comma
  . $space
  . addslashes($row['state'])
  . $spacer
  . addslashes($row['zipcode'])
  . $doublespacer
  . addslashes($row['description']) . "</div>');\n";

echo "map.addOverlay(marker);\n";
echo "\n";

I need to get $info to equal all of that so it can be passed correctly back to my script.

I am having a terrible time getting all the characters escaped. The semi-colons in particular resist all my efforts. Its got to be simple, but i can't seem to get it.

How can I get $info = "<all that stuff>";

?

Thanks in advance!

-Switchdoc

#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 21 August 2006 - 09:10 AM

not exactly sure what you are after BUT if $info has to contain the entire string that you generate (i.e. var point = ....) just do this....

$info =  "var point = new GLatLng(" . $location . ");";
$info .= "var marker = createMarker(point,\"$name\",'<div id=\"infowindow\" style=\"white-space: nowrap;\">"
  . addslashes($row['name'])
  . $spacer
  . addslashes($row['address'])
  . $spacer
  . addslashes($row['city'])
  . $comma
  . $space
  . addslashes($row['state'])
  . $spacer
  . addslashes($row['zipcode'])
  . $doublespacer
  . addslashes($row['description']) . "</div>');\n";

$info .= "map.addOverlay(marker);\n";
$info .= "\n";

echo $info;

now you have all that in info and can passs it anywhere you like.
follow me on twitter @PHPsycho

#3 switchdoc

switchdoc
  • Members
  • PipPip
  • Member
  • 22 posts
  • LocationColorado

Posted 21 August 2006 - 04:43 PM

Thanks for the reply! It's close but I am still running into an issue.

Here is what I am running into:

Here is an example of what I ultimately need outputted with all the variables added so its easier to see whats going on:

var point = new GLatLng(39.925512 , -105.086708);
var marker = createMarker(point,"Broomfield Location",'<div id="infowindow" style="white-space: nowrap;">Broomfield location<br>123 W smith<br>Broomfield,&nbsp;CO<br>80020<br><br>Email:<br>broomfield@company.com</div>');
map.addOverlay(marker);


Here is what I am getting with the example you provided:

var point = new GLatLng(39.925512 , -105.086708);
var marker = createMarker(point,"Broomfield Location",'
Broomfield location
123 W smith
Broomfield, CO
80020

Email:
broomfield@company.com
'); map.addOverlay(marker);



The <div .....> and </div> tags are gone. Is there a way to escape this so those stay? Its gotta be easy but I've thrown every \ at it I can think of and nothing :)

Thanks,

-Switch

#4 willpower

willpower
  • Members
  • PipPipPip
  • Advanced Member
  • 296 posts
  • LocationWarrington, Cheshire, UK

Posted 21 August 2006 - 04:59 PM

here the ' and the " are both escaping the string to be added

so the '<div..... is being escaped at '

so it should become


$info =  "var point = new GLatLng(" . $location . ");";
$info .= "var marker = createMarker(point,\"$name\",\'<div etc....
Wait...I've got it...Bollocks, it's gone again!

If at first you don't succeed....stop using ASP and get onto PHP

#5 switchdoc

switchdoc
  • Members
  • PipPip
  • Member
  • 22 posts
  • LocationColorado

Posted 21 August 2006 - 05:11 PM

I appreciate the reponse!

I've added the slash where indicated, but no joy.

Now I just get:

var point = new GLatLng(39.922512 , -105.087608);var marker = createMarker(point,"Broomfield Location",\'
Broomfield Location
123 w smith
Broomfield, CO
80020

Email:
broomfield@company.com
'); map.addOverlay(marker);


Basically it just shows the slash.. this kind of little stuff drives me nuts.

#6 jsimmons

jsimmons
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 21 August 2006 - 05:37 PM

</div>'

should be

</div>\'



#7 switchdoc

switchdoc
  • Members
  • PipPip
  • Member
  • 22 posts
  • LocationColorado

Posted 21 August 2006 - 05:43 PM

Again thanks for the reply.

Added the changes suggested by folks so far. Here again is the code:

$ssInfo =  "var point = new GLatLng(" . $location . ");";
$ssInfo .= "var marker = createMarker(point,\"$name\",\'<div id=\"infowindow\" style=\"white-space: nowrap;\">"
  . addslashes($row['name']) 
  . $spacer
  . addslashes($row['address'])
  . $spacer
  . addslashes($row['city'])
  . $comma 
  . $space
  . addslashes($row['state'])
  . $spacer 
  . addslashes($row['zipcode'])
  . $doublespacer 
  . addslashes($row['description']) . "</div>\');\n";

$ssInfo .= "map.addOverlay(marker);\n";
$ssInfo .= "\n";


And here is the result:

var point = new GLatLng(39.925112 , -105.087608);var marker = createMarker(point,"Broomfield Location",\'
Broomfield Location
123 w smith
Broomfield, CO
80020

Email:
broomfield@company.com
'); map.addOverlay(marker);



Still no div :(

Any other thoughts?

#8 switchdoc

switchdoc
  • Members
  • PipPip
  • Member
  • 22 posts
  • LocationColorado

Posted 22 August 2006 - 12:07 AM

*bump*




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users