passing values between frames -> parsing error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

passing values between frames -> parsing error

Post by jasongr »

Hello

I have a window call A.html that contains an iframe called B.php

B.php determines what its content should be in HTML and it holds that info in a PHP variable called $content

That means that the value of $content is now something like:

Code: Select all

<table border="2" cellspacing="0" width="100%">
  <tr>
    <td>
      <span style="font-family: 'Arial, Helvetica, sans-serif'>Hello</span>
    </td>
  </tr>
</table>
Note that the code contains both " and '

Now in the iframe onload event I want to pass the content of the $content variable to the innerHTML value of some div in A.html

I do the following:

Code: Select all

function onLoad() {
  var divElement = parent.document.getElementById('div');
  divElement.innerHTML = '<?php print $content; ?>';
}
Now note that the single ' that enclouses the value of the innerHTML. They interfere with the ' and " that are part of the content of $content

How can I solve this problem and pass any arbitrary HTML content between pages by using JavaScript?

regards
Help would be appreciated
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

on the page that prints out the javascript do
$content = str_replace("'", "This_is_a_single_quote", $content)

Then on the page that prints out content do this
$content = str_replace("This_is_a_single_quote", "'", $content)


Kind of a "make shift" way to get this done but i use this method alot, it replaces the quote with some text then changes it back later... you might wanna use something like %%qt%% instead of This_is_a_single_quote or something like that
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

My understanding is that Style does not need the single quote...

Code: Select all

<span style="font-family: 'Arial, Helvetica, sans-serif'>Hello</span>
but you might run into problems if the string is

Code: Select all

<span style="font-family: Arial, Helvetica, sans-serif>O'Reilly</span>
In the above code it would be better to htmlspecialchars the "O'Reilly".

Remember you can use the escape character \ in both Javascript and PHP.
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

Post by jasongr »

there is a problem with this solution because it assumes I can run PHP on the recieving side

remember that the transfer is made in JavaScript after the page loads which means that any processing must be done in JavaScript
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

CoderGoblin wrote:Remember you can use the escape character \ in both Javascript and PHP.
or if the content is always the same structure why not call a javascript function on the parent passing in the content. Th function would build the structure and place the smaller content.
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

Post by jasongr »

I need to know how to cause the following string:

Code: Select all

<span style="font-family:'ariel'">
   test
</span>
to transform into the following:

Code: Select all

<span style="font-family:'ariel'">   test</span
I need to replace all newlines with empty string or something.
How can I do it in PHP?
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

$string=str_replace("\n","",$string);
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

Post by jasongr »

thanks that solved my problem
Post Reply