Jump to content

Recommended Posts

So you want to loop through all the links on a page and apply css to a specific word or to the whole link?

 

To give a nudge in the right direction have a look at this example script for highlighting words in text

<style type="text/css">
.hightlight { color: red; background-color: yellow; }
</style>
<?php

// wraps word with span tag with hightlight class applied
function hightlight_word($word) {
	return '<span class="hightlight">' . $word[0] . '</span>';
}

// some dummy text
$text = '
I like cats and dogs.
cats like to each fish.
dogs like to chase cats.
';

// word to search for
$word = 'cats';

// search for word and apply highlight_word()
$text = preg_replace_callback("~\b$word\b~i", 'hightlight_word', $text);

// display text with highlighted word
echo nl2br($text);

?>
Edited by Ch0cu3r

No. Just detect a link with a certain word (for instance "section/usa" in a link) in the html code of a site, and then insert a css file or style in the index.php to be applied to the whole site.

 

The link (example = <link href="templates/section/usa.html" >USA</a>) is in the html code and the part ""section/usa" is what must be detected through php.

 

So the script would be in the index.php, searching for such words in all the links in a given page within the website.

Edited by jumasol

I have found this:

 

<?php
$ruta="http://www. sitio .com/index.php?option=com_xmap&view=xml&tmpl=component&id=1";
$dom=new DOMDocument;
$dom->preserveWhiteSpace= FALSE;
$dom->load($ruta);
$links=$dom->getElementsByTagName('descriptions');
foreach($links as $link){
echo '<link href="/css/xxxxxxxxxxxxxxxxxxx.css" rel="stylesheet" type="text/css" />';
}
?>

 

But does not work for some reason.

 

The sitemap link is correct and there is an hyperlink to "descriptions", but the script does not work.

 

Some comment?

This other option does not work either. And the url links to an html document:

 

<?php
$ruta="http://www. sitio .com/sitemap";
$dom=new DOMDocument;
$dom->preserveWhiteSpace= FALSE;
$dom->load($ruta);
$links=$dom->getElementsByTagName('descriptions');
foreach($links as $link){
echo '<link href="/css/xxxxxxxxxxxxxxxxxxx.css" rel="stylesheet" type="text/css" />';
}
?>

Do you understand what $dom->getElementsByTagName('descriptions'); is doing? It is trying find tags such as <descriptions></descriptions>, these do not exist in HTML. What specific tag are you looking for, post example html code you're wanting to find and what you want it to do with it.

No. What I am trying to detect link names in a sitemap. The sitemap might be an xml or html file. When a certain link with a given name is in the page, a css file would be included in the index.

 

Thus, and in this case, www. sitio com/descriptions in the sitemap.

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.