george Posted October 2, 2014 Share Posted October 2, 2014 (edited) Here is my code: The code fails at line 36: $txt = substr($mtcontent, 0, strpos($mtcontent, "</title>")+7); <!DOCTYPE HTML><html><head> <meta charset="utf-8"> <title>Untitled Document</title> <style type="text/css"> body { margin:20px; padding:0; background-color:#0000FF; color:#FFFF00; } </style></head><body><h3>/* make a copy of the file to parse for assurance */</h3><br><?php copy("C:UsersownerDesktopPLUcodes.htm", "C:UsersownerDesktopworkfile.htm"); if(!file_exists("C:UsersownerDesktopworkfile.htm")) { die("File not found"); } else { echo "got copy"; }?><br><h3>/* get a file handel for the workfile */</h3><br><?php $myfile = fopen("C:UsersownerDesktopworkfile.htm", "r") or die("Unable to open file!");?><h3>/* copy content of workfile into a var, $mtcontent, for parsing */</h3><br><?php $mtcontent = fread($myfile,filesize("C:UsersownerDesktopworkfile.htm"));?><h3>/* we don't need the file workfile.htm open anymore, so close it using the file handel for that file */</h3><br><?php fclose($myfile);?><h3>/* get the content of our string from the first byte up to the closing title tag */</h3><br><h3>/* well put it in a varable called $txt */</h3><br><?php $txt = substr($mtcontent, 0, strpos($mtcontent, "</title>")+7); echo $txt;?><h3>/* then add the string litteral <head><body> to the end of our string */</h3><br><h3>/* have to use the HTML code for the grater and less than symbols, else won't work */</h3><br><?php $txt .= '<head><body>'?><h3>/* lets see what we have */<h3><br><?php echo $txt;?></body></html> I have tried using strpos($mtcontent, "<⁄title>") instead of strpos($mtcontent, "</title>") But that causes the page to render strangely wrong. At the end of the page, I want to echo the variable txt, but it appears to be empty. Edited October 2, 2014 by george Link to comment Share on other sites More sharing options...
niche Posted October 2, 2014 Share Posted October 2, 2014 (edited) how does $txt echos? Edited October 2, 2014 by niche Link to comment Share on other sites More sharing options...
george Posted October 2, 2014 Author Share Posted October 2, 2014 Since the content of the variable I want to echo is HTML code, maybe there is some way I need to escape it, or echo it to a variable, and then populate an innerHTML with it? I do not want the HTML I am outputting to be used by the browser as HTML on the fly. I want to display the HTML as content. Link to comment Share on other sites More sharing options...
dsonesuk Posted October 2, 2014 Share Posted October 2, 2014 (edited) Are you trying to achieve output similar to this? <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>show html on page using php</title> </head> <body> <?php $mtcontent = '<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> </head> <body> </body></html>'; $txt = substr($mtcontent, 0, strpos($mtcontent, "</title>") + 8); ?> <pre> <?php echo htmlspecialchars($txt); ?> </pre> </body></html> Edited October 2, 2014 by dsonesuk Link to comment Share on other sites More sharing options...
george Posted October 2, 2014 Author Share Posted October 2, 2014 Thanks dsonesuk, I will try that now. Link to comment Share on other sites More sharing options...
george Posted October 2, 2014 Author Share Posted October 2, 2014 That was it dsonesuk. I only want to display the built string because I want to see if I made any mistakes, and sure enough, I did. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now