2

I made this website that uses XML file to store news entries. So basically a person will "submit" his name, date and content to the file and then I use DOM and for loop to print out the entries in homepage.

Anyway I'm planning to add WYSIWYG editor for the posting part but for now they're forced to use 'a' tags to make the links clickable. The problem is I noticed links that start with http:// works but links that start with www. doesn't. Is there a way to make both work using 'a' tags?

I'm still new to web development so I'm wondering if someone can help me.

$doc->load('entries.xml');
$newsArray = $doc->getElementsByTagName ('entry');

for($i = $newsArray->length; $i > 0; $i--)
{               

$ent = $newsArray->item ($i-1); 

$title = $ent->childNodes->item (1)->nodeValue;
$message = $ent->childNodes->item (2)->nodeValue;
$name = $ent->childNodes->item (3)->nodeValue;
$date = $ent->childNodes->item (4)->nodeValue;

if (get_magic_quotes_gpc()) {

   $message1 = stripslashes($message);
}
else {
    $message1 = $message;
}

echo "<div id='newsSec'>";
echo "<p></p>";
echo "<div class='newsTitle'> <b> $title </b> </div>";
echo "<div class='newsMessage'> " .nl2br($message1) ."</div>";
echo "<div class='newsName'> <b>Posted by:</b> $name <b>$date</b> </div>";
echo "</div>";
user977151
  • 495
  • 5
  • 9
  • 18

2 Answers2

2

Append double-slashes to the beginning of the URL. It will take the same protocol as the host-page itself

<a href="//www.google.com">...</a>

Reference: Protocol relative links: rfc1808

Anirudh Ramanathan
  • 46,179
  • 22
  • 132
  • 191
1

Add $message1 = "http://".$message1; before the echos. This will add the http:// in front of the link output.

Mooseman
  • 18,763
  • 14
  • 70
  • 93
  • The user may use http link or www link...depending on what he took so that's why I wanted to find an "automatic" solution but it looks like I'll just tell them to add extra // – user977151 Jan 20 '13 at 21:11