I am trying to insert the Javascript variable 'document.title' into a textarea i.e. <textarea rows="3" cols="25"><a href="<?php echo selfURL(); ?>" title="<script>document.print(document.title);</script>">Link</a></textarea> I also use PHP to grab the current pages URL (i.e. 'selfURL function') which removes the opportunity to print the entire line as a Javascript i.e. <script>document.print("<textarea rows="3" cols="25"><a href="currenturl.html" title=""+document.title+"">Link</a></textarea> I can grab the current URL with PHP and slot it into the links href no problem, its printing the global 'document.title' javascript variable into the links title attribute I can't do. Anyone know I could accomplish would I am trying to do? Or maybe even provide a simpler solution? Thanks in advance!
Never mind, figured how to do it with PHP. If anybody ever has this question again, since I had the URL already, all I need to do was write a function that opened the file source code, looped through it until it found the <title> tag, extract the title with a Regular Expression, and return: function Pagetitle($URL){ $FileHandle = fopen($URL, "r") or exit("Unable to open file"); $FileLine = ""; $TitleFound = FALSE; while(!feof($FileHandle)){ if($TitleFound == TRUE){ break; } $FileLine = fgets($FileHandle); if(strpos($FileLine, "title>") == TRUE){ $FileLine = preg_replace("/<title>(.*?)<\/title>/", "$1", $FileLine); $TitleFound = TRUE; } } fclose($FileHandle); return $FileLine; } PHP: Hope this helps anyone else with this problem, though suppose it should technically be moved to the PHP forum ...mods, do your will.
er, don't mean to be rude or anything but i just don't think this is a good solution at all - you are offloading work that the client browser can do to your server at the cost of cpu time & network lag, also subjugated to PHP's fopen restrictions (urls disallowed by php.ini by default) go back to your original problem and attempted solution and fix it... for instance, you can have: <textarea id="foo"></textarea> <script type="text/javascript"> // make sure this is after the textarea above or put it within your window.onload function document.getElementById("foo").innerHTML = "<a href='blah.php' title='"+document.title+"'>blah</a>"; </script> PHP: i am not sure if for the textarea we need the .innerHTML or .value property, try either if it does not work. using inline php does NOT in any way prevent you from using javascript, you can combine the two. for example, this is valid from within your main page but not within an external .js file: document.getElementById("foo").innerHTML = "<a href='<?=selfURL()?>' title='"+document.title+"'>blah</a>"; then again, you can do <script src="blah.php"></script> and use inline php as well.