Jump to content

how to link external files with php


tim@getdim

Recommended Posts

I know basically nothing about PHP but i have a few websites i manage that are built with PHP.

I plan to learn PHP but for the time being learning Javascript has a wider range of usability for me.

 

That being said,

 

Im trying to link to an XML sitemap using php.

 

in html i would use

<link href="sitemap.xml" />

 

how can i do this in PHP?

 

I have searched google and such for how to do this but was unable to find an explanation that i could understand as relating to my need.

Link to comment
Share on other sites

I hope you wouldn't do that, as that's not valid html. The HTML for a link is

<a href="url.etx">Link Text</a>

. I don't know XML so I don't know if you're accidentally doing XML and calling it HTML.

 

That said, PHP can print HTML, or you can include raw HTML in php. You can't find out how to do it because you're asking the wrong question.

 

<?php
echo '<b>This is bold text</b>';
?>
or
<?php
//Your php code here
?>
<b>This is my bold html</b>
<?php
//more php in here
?>

Link to comment
Share on other sites

Actually its perfectly valid HTML - its the same way you link a stylesheet.

It works perfectly fine in every other site ive used it in.

 

I actually just figured out what my problem was.

 

i had tried to use raw html outside the

<?php

tag but it was causing error messages when i uploaded the file.

turns out i had the wrong file. the site in question is using the MODx CMS which i am not familiar with - but after searching through the file structure for a while i was able to find the file that was generating the html for the index page. once i put in my html code there right underneath the stylesheet links, it worked perfectly fine.

 

Thanks for your time, though. Sorry it turned out to be unneeded.

Link to comment
Share on other sites

The way it was worded it sounded like a link in the body, not linking a document in the head. I see what you're talking about now.

Everything I've read says <link> is not heavily supported for anything other than stylesheets, but if it is working for you then go ahead.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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