?
Solved

add text to .html pages

Posted on 2006-07-19
16
Medium Priority
?
286 Views
Last Modified: 2008-02-01

hello experts,

what i want to accomplish is this:

a user types an url (for example www.isoftware.nl/EE_dump/Q_21917670.html)
they get to see this page, but i want to include a link in this page
preferred is the way google does this, with an frame on top

how can i do this?
(i do not want to hard code this link, because there are more files to come
0
Comment
Question by:Mark_FreeSoftware
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
  • 3
  • +1
16 Comments
 
LVL 18

Expert Comment

by:bruno
ID: 17142978
you want to hijack someone elses website?
0
 
LVL 13

Author Comment

by:Mark_FreeSoftware
ID: 17144351

no, i want to do that with my own website
0
 
LVL 13

Author Comment

by:Mark_FreeSoftware
ID: 17144354

i use the directory EE_dump for html examples that i use on this site
but i want to bring some structure in it
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 18

Expert Comment

by:bruno
ID: 17145116
i guess i don't understand what you are looking to do then - can you clarify a bit?
0
 
LVL 3

Expert Comment

by:jayleew
ID: 17145167
<frameset rows="20%, 80%">
     <frame src="url to your link html formatted">
     <frame src="link url">
</frameset>

I'm not sure what you are trying to do, but if a user is typing a url into a field of some sort you must use a scripting language.

0
 
LVL 13

Author Comment

by:Mark_FreeSoftware
ID: 17145304

take a look at this link in firefox:
http://www.isoftware.nl/EE_dump/Q_21917670.html

that is what i want
(it still doesnt work in internet explorer)

the 500 points are now for the one that can help me with this:

for the View Source link,
i am reading the page like this:

$open = fopen("$file", "r");
$size = filesize("$file");
$content = fread($open, $size);

however when i echo that $content inside a div, it is displayed as normal html
how can i paste this as plain text?
0
 
LVL 18

Assisted Solution

by:bruno
bruno earned 400 total points
ID: 17146038
display it in a textarea...
0
 
LVL 6

Accepted Solution

by:
davbouchard earned 800 total points
ID: 17148100
You can use the php function htmlentities() so you'll output code.
It changes for exemple :

I'll "walk" the <b>dog</b> now
to
I'll &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; now
0
 
LVL 3

Expert Comment

by:jayleew
ID: 17148244
Okay, from your code you are trying to print the contents of a file, of course the file you are reading is HTML.

So, you want a text view of the file.  Does that include the HTML tags?

Brunobear has a great idea, a textarea would not render the HTML, leaving the plain text: HTML tags and all.  At least that is the easiest fix.  

Otherwise, you will have to encode the special characters like davbouchard says.
0
 
LVL 13

Author Comment

by:Mark_FreeSoftware
ID: 17148511
>>So, you want a text view of the file.  Does that include the HTML tags?
yeah

only problem is now that there are no newline characters?

formatting is all screwed
0
 
LVL 3

Assisted Solution

by:jayleew
jayleew earned 800 total points
ID: 17149029
Yup, if you want to retain the newline formatting, you will have to replace all newline characters read in with a "<br>" to display correctly in a browser.

str_replace() can accomplish this task.

Remember, if you are offering editing features to save the file, you have to replace the "<br>" with "/n" again as well as decode the string back to the original.


If you don't feel like parsing the input data for new lines (shouldn't be that difficult), you can also read the file in line by line instead of the entire contents like you are doing.  

Put a loop till the end of file and repeat:
   readline, convert all special characters, write to screen, write <br>
0
 
LVL 13

Author Comment

by:Mark_FreeSoftware
ID: 17149322

when i use that str_replace, and i output the text:
whenever a user copies the text and paste it in another program, will the formatting be normal?
0
 
LVL 3

Expert Comment

by:jayleew
ID: 17149397
If they are copying straight from the browser window and not the source file generated by your code, yes the newlines will be preserved according to the line breaks on the screen, rendered from the browser.  

The software program they plop it in will be responsible for wrapping text, if it is necessary.

0
 
LVL 13

Author Comment

by:Mark_FreeSoftware
ID: 17149444

found this php function:
nl2br()
it will insert a <br> before each newline

(found it by googling for str_replace "<br" "\n" so it "came from" jayleew)



thanks for your help experts!

in my next post i will post the solution to my question for future reference,


now for the points,
this is going to be a split between
brunobear,
jayleew,
davbouchard
0
 
LVL 13

Author Comment

by:Mark_FreeSoftware
ID: 17149529

example url:
www.isoftware.nl/EE_dump/Q_21917670.html

first i moved all files to a subdir of the one (EE_dump) that will be referred to
then created a .htaccess file in it, with these contents:

======start cutting below this line======
RewriteEngine on
RewriteRule ^([Qq]_[0-9]+)[.](htm|html|php|css])(.*)$ display.php?dis=$1.$2$3
======stop cutting above this line======
this will force the server to redirect all pages that start with Q_ or q_ followed by more than one number with one of the following extensions: htm, html, php,css
to the php page display.php

examples:
http://www.isoftware.nl/EE_dump/Q_21917670.html             --->  http://www.isoftware.nl/EE_dump/display.php?dis=Q_21917670.html
http://www.isoftware.nl/EE_dump/Q_21917670.html&src=1  --->  http://www.isoftware.nl/EE_dump/display.php?dis=Q_21917670.html&src=1

then created a file (display.php) that would check for the var "dis" in the dir the files are in, and copy the code to a buffer
then outputted the buffer directly into a div if no value for src is specified or src != 1 ,
or if src == 1 then used the functions htmlentities() and nl2br() to format the text and display the code

!they need to be used with htmlentities() first, because htmlentities() strips out the formatting inserted by nl2br()!


i hope this makes any sense

mark
0
 
LVL 13

Author Comment

by:Mark_FreeSoftware
ID: 17149538

and don't forget to include this .htaccess in the subdir where the real files are located!

======start cutting below this line======
RewriteEngine on
RewriteRule ^.*$ -
======stop cutting above this line======

this disables the redirecting!!
0

Featured Post

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question