Thanks for the quick reply Brak, I appreciate it.
I'm still learning both PHP and JavaScript and have taken the code
from an example, so I don't know how to decode the "description"
variable in my JavaScript.
I guess it's this code I have to reverse:
function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','<',$htmlStr);
$xmlStr=str_replace('>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&',$xmlStr);
return $xmlStr;
}
I tried reversing the process by adding this function to my
JavaScript:
function parseToHTML($xmlStr)
{
$htmlStr=str_replace('<','<',$xmlStr);
$htmlStr=str_replace('>','>',$htmlStr);
$htmlStr=str_replace('"','"',$htmlStr);
$htmlStr=str_replace("'",''',$htmlStr);
$htmlStr=str_replace("&",'&',$htmlStr);
return $htmlStr;
}
And then changing the description variable line like this:
var description = parseToHTML(markers[i].getAttribute("description"));
After that the map didn't load, so I guess I'm doing it totally wrong.
Care helping me out?
I agree that it would be more intuitive to put my description as the
content of my marker tag, but as I'm still learning I don't want to
risk messing the code up so I don't want to change anything until I
have a better grasp on things.
On 9 mar, 16:03, Brak <[email protected]> wrote:
> In your PHP you are encoding your < and > to HTML entities. You need
> to do the reverse to your "description" variable in JavaScript. They
> come from your PHP/XML as entities and if just printed in a web
> browser, would show their < and > characters and not be interpreted as
> HTML tags. Decode them and you should be good to go.
>
> On a side note, it may be more intuitive to put your description as
> the content of your <marker> HERE </marker> tag. You'd still need to
> encode and decode it, but it may fit better as content rather than an
> attribute. Just a thought.
>
> On Mar 9, 9:39 am, Daniel <[email protected]> wrote:
>
> > Hi,
> > My markers are generated via XML with content that contains <a href>
> > links. In the InfoWindows the html links are displayed as regular
> > text, so instead of a link I get the whole <a href="">link</a>. Is
> > there a way to fix this? I've searched around but haven't found a
> > clear answer. Would be really grateful if someone could help me with
> > this.
>
> > Here's a link to the website:
> > Map:http://tresuri.com/big-map/
> > Javascript-file:http://tresuri.com/wp-map/bigmap.js
> > XML-generator:http://tresuri.com/wp-map/generatexml.php
>
> > XML-generator code:
>
> > <?php
> > require("C:/xampp/htdocs/tresuri/wp-map/dbinfo.php");
> > require( 'C:/xampp/htdocs/tresuri/wp-load.php' );
>
> > function parseToXML($htmlStr)
> > {
> > $xmlStr=str_replace('<','<',$htmlStr);
> > $xmlStr=str_replace('>','>',$xmlStr);
> > $xmlStr=str_replace('"','"',$xmlStr);
> > $xmlStr=str_replace("'",''',$xmlStr);
> > $xmlStr=str_replace("&",'&',$xmlStr);
> > return $xmlStr;
>
> > }
>
> > // Opens a connection to a MySQL server
> > $connection=mysql_connect (localhost, $username, $password);
> > if (!$connection) {
> > die('Not connected : ' . mysql_error());
>
> > }
>
> > // Set the active MySQL database
> > $db_selected = mysql_select_db($database, $connection);
> > if (!$db_selected) {
> > die ('Can\'t use db : ' . mysql_error());
>
> > }
>
> > // Select all the rows in the markers table
> > $query = "SELECT id,object_id,post_title,post_content,post_name,type
> > FROM wp_posts, wp_term_relationships WHERE id=object_id AND
> > post_status='publish' AND post_type='post' AND term_taxonomy_id=3";
> > $result = mysql_query($query);
> > if (!$result) {
> > die('Invalid query: ' . mysql_error());
>
> > }
>
> > header("Content-type: text/xml");
>
> > // Start XML file, echo parent node
> > echo '<?xml version="1.0" encoding="UTF-8"?>';
> > echo '<markers>';
>
> > // Iterate through the rows, printing XML nodes for each
> > while ($row = @mysql_fetch_assoc($result)){
> > $post_id = $row['object_id'];
> > $single = true;
> > $lat = get_post_meta($post_id, marker_lat, $single);
> > $lng = get_post_meta($post_id, marker_lng, $single);
> > $type = get_post_meta($post_id, type, $single);
>
> > // ADD TO XML DOCUMENT NODE
> > echo '<marker ';
> > echo 'name="' . parseToXML($row['post_title']) . '" ';
> > echo 'description="' . parseToXML($row['post_content']) . '" ';
> > echo 'permalink="http://tresuri.com/'. $row['object_id'] . '/' .
> > parseToXML($row['post_name']) . '" ';
> > echo 'lat="' . $lat . '" ';
> > echo 'lng="' . $lng . '" ';
> > echo 'type="' . $type . '" ';
> > echo '/>';
>
> > }
>
> > // End XML file
> > echo '</markers>';
> > ?>
>
> > Regards,
> > Daniel
--
You received this message because you are subscribed to the Google Groups
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-js-api-v3?hl=en.