Jump to content

Help with echo


switchdoc

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/18152-help-with-echo/
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/18152-help-with-echo/#findComment-77953
Share on other sites

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:

[quote]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>[email protected]</div>');
map.addOverlay(marker);[/quote]

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

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

Email:
[email protected]
'); map.addOverlay(marker); [/quote]


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
Link to comment
https://forums.phpfreaks.com/topic/18152-help-with-echo/#findComment-78153
Share on other sites

I appreciate the reponse!

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

Now I just get:

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

Email:
[email protected]
'); map.addOverlay(marker);
[/quote]

Basically it just shows the slash.. this kind of little stuff drives me nuts.
Link to comment
https://forums.phpfreaks.com/topic/18152-help-with-echo/#findComment-78164
Share on other sites

Again thanks for the reply.

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

[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";[/code]


And here is the result:

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

Email:
[email protected]
'); map.addOverlay(marker); [/quote]


Still no div :(

Any other thoughts?
Link to comment
https://forums.phpfreaks.com/topic/18152-help-with-echo/#findComment-78188
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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