0

I have a page that calls content into the page from a third party using javascript. What I need to do is preg_replace or str_replace the output for the purposes of translating a few words (ie days of the week from English to Spanish). Here is an example of the javascript call:

<script language="javascript" src="http://www.example.com/?id=100&amp;site=1&amp;plugin=result_type1&amp;<?= $queryParams ?>">
</script>

The js outputs the results into an html table. Is this something that is even possible? I don't have more code because I wouldn't know how to go about starting something like this.

Any help is appreciated.

NotJay
  • 3,919
  • 5
  • 38
  • 62
  • 2
    php doesn't execute js. you'd have to use an ajax call to send the results of this 3rd party script to your server. e.g `$.post('yourserver.php', $('#where_the_script_wrote_stuff').html());` – Marc B Feb 21 '13 at 20:40
  • That's what I was afraid of. Thanks Marc. I appreciate the advice. – NotJay Feb 21 '13 at 20:42
  • I can go about it the long and difficult way and scrape the feeds and store them in the database so then I can do whatever I want with it but the reality is... that is way more work than it is worth. Apparently they're working on a fix for me, just not sure how long it will take. I appreciate everyone's input and I did review the suggested existing question. Learned a little but ultimately it didn't help my situation ;-) Will keep this open for other suggestions anyhow. – NotJay Feb 21 '13 at 21:02

1 Answers1

0

Presumably the script you are loading injects HTML elements into your page. Once the page has loaded, use your browser to view the source to see which elements these are and what attributes they have.

One way of achieving what you want is to do an str_replace on the innerHTML property of the element you want. You could trigger the event with something like <body onload="doReplace()"> where doReplace is a function you write to handle the str_replace.

I'm assuming you don't have control over the resource you are injecting. If you do, far better to do the translation before the injection rather than live on the page. If you don't, you also run the risk of changes to the injected code ruining your doReplace function without notice.

Otherwise, you can try just downloading the script and changing it to suit your needs. You can then use your customized script on the pages which need a customized output.

deau
  • 1,193
  • 1
  • 9
  • 14