1

i have a slightly procedural problem,

I have a php based server. Basically i send a string to the server php file ( server.php file), this php file, performs some operations on this string and will then return the new string.

I want to add some js to the server.php file, which will run a few jquery dom traversing functions on the string. The string is a DOM.

I know that this is not what js was designed for,, i know that its supposed to only run on the browser,, but is there a simple workaround that i can do?

the string would look like this:

<body>      
<em>
    heres a em and this works as well

</em>
<p>
   here is another para and it works , BUT NOW LOOK AT THE NEXT LINE
    <br>
       where is this prepend,no prepend here, ladies and gentlement,,NADA.

</p>
<button onclick = "addtags()">here is the magic</button>

 </body>

so i need to do some, stuff on this via php, and then some aditional tree traversing,, and i love the jquery functions for this,, I;m using the .text() , .contains(), .before(), .after(), .attr('class') functions from jquery,, and if anyone can suggest any alternatives, its fine with me.. Can all this be done in XPATH??? i have no idea.. for me jquery works perfect. Would i need to create a new .html file from the string that i receive and somehow run the js on that??

Best Regards, RIchard.

1
  • 1
    When you can, just add the answer below and close out your question. Commented Feb 16, 2013 at 23:18

2 Answers 2

1

You cannot run js an php at the same time on the server. Theoretically it could be done, but not in the same execution flow.

You can do DOM processing in php.

Sign up to request clarification or add additional context in comments.

1 Comment

Honestly this is the "most correct" way to do it. Parse the DOM in PHP.
0

You can use PHP to echo javascript code to run on the client, but you cannot intermingle javascript and PHP in terms of execution on the server (unless you use some sort of interpreter like v8js).

Why can't you traverse your strings with PHP code? If you really want to use javascript then use jquery to make an ajax call to your PHP file. Then manipulate the returned string in jquery however you need to.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.