We help IT Professionals succeed at work.

Scan page and replace text

Luv2Muff
Luv2Muff asked
on
Hi,

Hoping someone can help with this.

First I want to look up the text contained in <meta name="keywords" content="FOO" />

Then I want to replace all instances in the page of the text "XXXX" with above.

So for example:

"This is the XXXX page text"

will become:

"This is the FOO page text"

Is this possible?


Comment
Watch Question

I'm confident it's possible but I don't believe I understand the problem.

It sounds like you want to change all instances of XXXX in a file with FOO.  Is that correct?

Open the source file for reading

Open a temporary file for writing

For each line read, use str_replace() to change any instances of XXXX with FOO and write to the temporary file.  

When done, remove source file.

Rename temporary to source file name.

Does that sound like what you want to do?  If so, do you need more help?  If not, what do you want to do?

Commented:
<script>
$(function(){
var keywords = $('meta[name=keywords]').attr("content");
$(document).ready(function(){  
      $('.replaceme').replaceWith(keywords);
      });
});
</script>

This is the <span class="replaceme">XXXX</span> page text

Author

Commented:
Thanks