Results 1 to 10 of 10

Thread: Getting Span Contents

  1. #1
    Join Date
    Mar 2010
    Posts
    27
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Getting Span Contents

    Hi All,

    I need to get the contents of a span object using PHP. This span resides two levels up (parent.parent). I haven't been able to find an example anywhere and my clumsy attempts have failed.

    is there a PHP counterpart for:

    Code:
     var data = document.getElementById('hud2').innerHTML;
    Last edited by djr33; 10-13-2012 at 07:00 PM. Reason: fixed [code] tag

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    Could you post an example? I think I know what you are talking about and this would require PCRE to retrieve the data, but I want to see an example to be sure.
    To choose the lesser of two evils is still to choose evil. My personal site

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I don't really follow this request either. As far as I can tell, it's completely impossible. HTML doesn't contain "objects" for PHP-- instead, it just generates text. Javascript, on the other hand, operates within the HTML page and treats objects on the page as objects/things.

    You can ask PHP to take some HTML text and look at it like that, but not while it's generating the page, at least not easily.

    If you're trying to use PHP to parse another page, that would be where this could apply potentially; but if you're trying to do this while you echo/print text to the browser, it just doesn't work like that.

    I'm sure there's some way to do what you're trying to do, but from your post it sounds like you need to understand the fundamentals of PHP a little more before attempting it-- if you can post some examples here that will help. What James said may help too; but I'm just not sure yet.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Mar 2010
    Posts
    27
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    hey thanks guys,

    I thought i was clear, but I guess not. Ok, 'object' was the wrong thing to use, but I was thinking along the lines of javascript, which does.

    So, here is what I have...

    A web page with a span containing the text 'x of y' (where x and y are integers as in 3 of 12).

    The same page has an iFrame.

    Inside that iFrames web page is another iFrame. Or nested iFrames...

    The innermost iFrame is generated by PHP and I need the contents of the span in the outermost page ('x of y').

    Simply put; is there a counterpart for 'document.getElementById('span id').innerHTML;'? Or in my case, 'parent.parent.document.getElementById('span id').innerHTML;'. This does work in JS.

    I do understand the difference in PHP and JS and I can't pass the value because of the intermediate page. My last resort may be using a session var, which I'm trying to avoid for no particular reason.

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Simply put; is there a counterpart for 'document.getElementById('span id').innerHTML;'? Or in my case, 'parent.parent.document.getElementById('span id').innerHTML;'. This does work in JS.
    That's logically impossible in PHP, because PHP doesn't work like that. There's no way to even conceptualize "parent" in PHP, because PHP doesn't work that way.

    You can find a way using string functions or some sort of HTML parser to take HTML, extract an element, then tag out the text from the middle of it, but that first requires getting the full text of that page within PHP.

    I'm still not sure I follow the situation-- you can't access an iframe using PHP, because again that's just not something that exists in PHP.

    If you can use a session var, that's a reasonable way to do. There may be other ways, but how would it look with sessions? And why do you want to avoid it? Maybe we can help to find another way.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Mar 2010
    Posts
    27
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks again,

    Yeah, I wasn't aware of any way, but that did mean there wasn't, so I thought I'd ask. I try to avoid too many Session vars, just so I don't abuse them. One more won't hurt...

  7. #7
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    You can use something like the DOMDocument class, but it's fairly complicated. You'd probably be better off using javascript (on the client side) to get the contents, and then passing them to php (on the server) directly.

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Here's what I'm confused about: how do you get it into the session var in the first place? If you already can do that, I don't see what the problem is. What you posted above (the JS example) looks like a way to get data. If that's not the problem, then post more information about what you're trying to do with it.

    Traq, that works, but only when dealing with HTML inside a string variable; I'm confused at this point about whether that's the situation or not. You can't use those functions to look at the parent of the last-created HTML element via PHP, while PHP is generating the HTML. That's what I'm failing to understand here.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by aztech4mac View Post
    A web page with a span containing the text 'x of y' (where x and y are integers as in 3 of 12).

    The same page has an iFrame.

    Inside that iFrames web page is another iFrame. Or nested iFrames...

    The innermost iFrame is generated by PHP and I need the contents of the span in the outermost page ('x of y').
    Are you trying to get the value from the "outermost" page and put it in the "innermost" page?

    Get the span value using javascript, then put it in a query string in the url of the iframe in question:
    Code:
    var data = document.getElementById('hud2').innerHTML;
    document.getElementById( 'myiframe' ).src = 'http://example.com/somepage.php?data=' + data;
    it's far more complicated because you have several nested iframes, but I think it can still be done. Just not sure how.
    Edit:
    Quote Originally Posted by http://stackoverflow.com/questions/1088544
    Code:
    var iframe = document.getElementById('iframeId');
    var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
    I haven't tried it, but there's your concept.
    You'll still need to pass the data to the PHP script that generates the page in that iframe (obviously, *before* it generates it, so you'll probably need to use javascript to create the iframe in the first place).


    Quote Originally Posted by djr33 View Post
    Here's what I'm confused about: how do you get it into the session var in the first place? If you already can do that, I don't see what the problem is.
    right - in any case, if you can do that, do do that (hahaha, I said do do) - that's what sessions are for, passing data between pages.

    Quote Originally Posted by djr33 View Post
    Traq, that works, but only when dealing with HTML inside a string variable; I'm confused at this point about whether that's the situation or not. You can't use those functions to look at the parent of the last-created HTML element via PHP, while PHP is generating the HTML. That's what I'm failing to understand here.
    actually, I'm not quite understanding that either, now that I re-read it...? but you're absolutely right
    Last edited by traq; 10-14-2012 at 03:46 AM. Reason: found more info

  10. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You actually can use javascript if the pages are all on the same domain. On the top page:

    Code:
    <span id="xofydata">5 of 7</span>
    On the nested page, regardless of how deeply it's nested:

    Code:
    <span id="xofydata"></span>
    <script type="text/javascript">
    document.getElementById('xofydata').innerHTML = top.document.getElementById('xofydata').innerHTML;
    </script>
    Untested, should work.

    Edit: I've since tested this and it works fine.
    Last edited by jscheuer1; 10-15-2012 at 05:22 AM.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  11. The Following User Says Thank You to jscheuer1 For This Useful Post:

    traq (10-14-2012)

Similar Threads

  1. What is the span tag?
    By pauldhilip in forum HTML
    Replies: 3
    Last Post: 05-13-2009, 05:23 PM
  2. span tag
    By fenway in forum Looking for such a script or service
    Replies: 3
    Last Post: 02-07-2007, 09:09 AM
  3. SPAN width in FF
    By mburt in forum CSS
    Replies: 11
    Last Post: 08-19-2006, 02:19 AM
  4. Difference between span and div
    By sathishhc in forum HTML
    Replies: 2
    Last Post: 07-26-2006, 05:15 AM
  5. <span>
    By bubba.daniel in forum HTML
    Replies: 10
    Last Post: 08-03-2005, 06:23 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •