Nov 8, 2009
Pages: 1, 2

Html Within Php Coding - Is there a way to read HTML Code?

free web hosting

Read Latest Entries..: (Post #11) by tuddy on Aug 14 2005, 08:15 AM.
QUOTE(karlo @ Aug 13 2005, 08:08 PM)I suggest using the include() function.. anyways, try using the QUOTE bbCode when posing a PHP code. Because a moderator or an Admin might warn you. How would i use include() within my script? I dont want any of the script to show something in the browser, which what include() would do, wouldn't it?The way to get rid of my errors is to have the values replaced, but why won;t my script replace them?, it just writes over everything with a blank page. :S...
read more.
Read the FIRST post of this Topic. - Express your Opinion! Contribute Knowledge :-).

Open Discussion > MODERATED AREA > Computers > Programming Languages > PHP Programming

Html Within Php Coding - Is there a way to read HTML Code?

tuddy
Is there a way to have PHP read a text file, which contains HTML Code, not text to display. This way i have a simple code in every page, linking to this text file, and then if i'm wanting to change the code, i only need to change the code in the text file. If that all makes sense? biggrin.gif

I get the feeling it can be done, but the only code i have seen is one that displays the contents of the text files.

Comment/Reply (w/o sign-up)

Tyssen
You can use PHP includes. Place this wherever you want your file to appear:

CODE
<?php include ("$path/yourfile.inc"); ?>

.inc is the suffix for include, but you can include any sort of file: .htm, .php, .txt etc. You can put whatever you want in your include. Place the link to the include on multiple pages, then when you want to update them all, you just update one file.

Comment/Reply (w/o sign-up)

tuddy
Thanks..Great help.

Will it work with .doc .xml .rtf ?? I'm guessing not through mmm...Thanks again!

Comment/Reply (w/o sign-up)

Tyssen
QUOTE(tuddy @ Aug 9 2005, 03:54 PM)
Will it work with .doc .xml .rtf ?? I'm guessing not through mmm...Thanks again!

It probably still will but because .doc and .rtf are made up of formatting information that you don't see on screen when you view the document, that stuff will end up in your page as gobbledegook.

Comment/Reply (w/o sign-up)

tuddy
WooHoo...I got it to work just fine, thank you so much.

Now for my next question, here is what i got. i got one page that calls up the form, then another that calls the php file that has the script. Is there a way i can mail the called file with the data inserted into it?

Take alook HERE to understand more tongue.gif..Just enter some random stuff!

Comment/Reply (w/o sign-up)

Tyssen
Your link doesn't work, but I think you're talking about emailing the contents of a form filled out by a user. You can definitely do that, but as I'm more familiar with ASP than PHP, I wouldn't really be able to help you out.
There are two ways of doing it though: processing the form with another PHP file or processing it with the same file as contains the form. The latter method is called a self-referencing form and is good for recording and printing errors to the screen before the form data is submitted.
Just do a search on 'php form email' in Google and you'll come up with lots of info.

Comment/Reply (w/o sign-up)

tuddy
Thanks, it work alittle, but not properly. so i have thought of another way to do it.
All this will be done by the one form processer (PHP Page)

1) Open the text file. (This text file contains HTML Code with 'placeholders for where the form data will be submitted in place of.)
2) Write the form data to the text file, replacing only the placeholders.
3) Then save it as a new file, but changing it to (something.html) everytime, to the server.
4) Then have a Email send the 'new' file as an attachment.
5) Then delete the 'new' file from the server ready for the next form to be submitted.

Opening the file i can do.
Replacing placeholders i can have a crack at.
but i get stuck again with, How do i save it as a new file, and change the file type?

Comment/Reply (w/o sign-up)

tuddy
Oh and i forgot, thanks Tyssen, your helpwas great, helped me with displaying the form back to the user after they submitted it. and sorry the link didn't work, i just looked at the link and i out .htm instead of .php which it is. sorry!

Comment/Reply (w/o sign-up)

tuddy
I have the following code now,

CODE
<?php
$file1 = 'files/leave.txt';
$file2 = 'files/leave1.txt';
$file3 = 'files/leave1.htm';

copy ($file1, $file2);

$from=array();
$from[]="<<number>>";
$from[]="<<rank>>";
$from[]="<<initials>>";
$from[]="<<family>>";
$from[]="<<datef>>";
$from[]="<<datet>>";
$from[]="<<dates>>";
//and so on to have all the fields you want to replace

$to=array();
$to[]=$number;
$to[]=$rank;
$to[]=$initials;
$to[]=$family;
$to[]=$datef;
$to[]=$datet;
$to[]=$dates;
//And so on to have all the strings you have to put in place of the fields

$string=str_replace($from,$to,$string);
$fp = fopen( "$file2" , "w" );
fputs( $fp, $string );
fclose( $fp );

copy ($file2, $file3);
$fileatt = "files/leave1.htm"; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$fileatt_name = "leave1.htm"; // Filename that will be used for the file as the attachment

$email_from = "Test"; // Who the email is from
$email_subject = "Leave Application"; // The Subject of the email
$email_message = "This is a Leave Application."; // Message that the email has in it

$email_to = "cm44750@cadetnet.gov.au"; // Who the email is too

$headers = "From: ".$email_from;



$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";

$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message . "\n\n";


/********************************************** First File ********************************************/


$fileatt = "files/leave1.htm"; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$fileatt_name = "leave1.htm"; // Filename that will be used for the file as the attachment

$file = fopen($fileatt,'rb');
$data = fgets($file,filesize($file));
fclose($file);


$data = chunk_split(base64_encode($data));

$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";

/********************************************** Second File ********************************************/

// To add more files just copy the file section again, but make sure they are all one after the other! If they are not it will not work!


$ok = @mail($email_to, $email_subject, $email_message, $headers);

if($ok) {
echo "<font face=verdana size=2>The Leave Application was successfully sent!</font>";
} else {
die("Sorry but the Leave Application could not be sent. Please go back and try again!");
}

unlink( "$file2" );
unlink( "$file3" );

?>


Now the problem i face is the errors i get with it. these errors being:

QUOTE
Warning: filesize(): Stat failed for Resource id #7 (errno=2 - No such file or directory) in /home/tuddy/public_html/pro.php on line 78


QUOTE
Warning: fgets(): Length parameter must be greater than 0. in /home/tuddy/public_html/pro.php on line 78


Line 78 is: $data = fgets($file,filesize($file));

I have studied and changed this code around and can't get it to work, the attachment i get is blank, but its supposed to have the placeholders replaced?

Any ideas?

Notice from cmatcmextra:
Added codebox and quote tags. Warned. Also I'm deducing the credits earnt for this post.

 

 

 


Comment/Reply (w/o sign-up)

karlo
I suggest using the include() function.. anyways, try using the QUOTE bbCode when posing a PHP code. Because a moderator or an Admin might warn you. sad.gif

Comment/Reply (w/o sign-up)

Latest Entries

tuddy
QUOTE(karlo @ Aug 13 2005, 08:08 PM)
I suggest using the include() function.. anyways, try using the QUOTE bbCode when posing a PHP code. Because a moderator or an Admin might warn you. sad.gif
*



How would i use include() within my script? I dont want any of the script to show something in the browser, which what include() would do, wouldn't it?

The way to get rid of my errors is to have the values replaced, but why won;t my script replace them?, it just writes over everything with a blank page. :S

Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Pages: 1, 2
Similar Topics

Keywords : html, php, coding, read, html, code

  1. Weird Formatting: Embedding Php Into Html
    (10)
  2. Php Code For Login Form With Validation In Php
    (7)
    I dont want to use javascript as a validation form i want to use Regular expression in PHP for Login
    or other page. please any one have a best code for validation in PHP. as i thinks that web site
    Validation on server site is faster then client site validation. Most welcome.....
  3. Create Table - Mysql Code - Help
    (1)
    I need your feedback about setting the database issues. Please, review them and correct some entries
    in the code if they got some mistakes. This is the code itself: SQL CREATE TABLE `news` (
    `id` int(250) NOT NULL auto_increment, `title` varchar(255) NOT NULL default '',
    `text` text NOT NULL, `author` varchar(255) NOT NULL default '', `valid` varchar(255)
    NOT NULL default '', `date` varchar(255) NOT NULL default '', PRIMARY KEY
    (`id`) ) ENGINE = MyISAM ; ....
  4. Php Source Code Unveiled In Browser?
    is that possible? (7)
    I am quite new to PHP and this concern came to my mind after playing around a bit with it... When
    PHP is not correctly configured on the web server the source code of a php file we try to access
    through a browser will be shown instead of the result of the code itself. This will normally not
    happen when PHP is working properly, but I was just wondering if it could still be possible to see
    that code if a user wanted to or if something on the server failed. This would for example expose
    sensitive information like mysql passwords and so on... Is anything like that possib....
  5. Coding Help!
    Need Tutorial?! (3)
    Hey, guys... How can I build the following things. I already made the simple administrator page
    where I may add some news to the web-site, but I need to make one more things described below.
    Please, help me if you can. This is the way how it has to work. The process is described by two
    things of the illustrations: The first picture (or brief description of the news) will be
    somehow placed on the main page, the main page may have several of those things. On the first
    picture, you may see that is marked by red named : "Full Descr." that I mean full descriptio....
  6. Html Form!
    Using MySQL?! (4)
    Hey, I need your help again! I need some good working tutorial how I can update my SQL through HTML
    form. I did use some tutorials online found with the help of google; but they do not work properly;
    I mean there are still small mistakes. I need to have a good tutorial to follow. It should be
    based on security and more things. It has to be done in proper way.......
  7. Malicious Code Injection
    (3)
    Hi everyone! This is my first post, so be kind! Basically, I'm trying to get a free host
    together so am writing some posts. Here's a little summin' summin' about malicious code
    injection with PHP applications. Basically, this security exploit is one of the oldest tricks in
    the books and all comes down to the fact that PHP allows execution of both local and remote scripts
    with the SAME function... dur. Anyway, this is how it works. Image you've just employed a young
    go getter, straight outta uni, who has found becoming a Jack of all trades a sinch. Y....
  8. Php And Mysql Programming
    anyone knows a code for mysql and php (2)
    hi everyone! I am making a program using php and mysql...I am a noob on this so i need your help
    guys...I want to make a simple program that will some values and then store them on a database and
    then retrieve them...uhmm let me give an example out put of what i need. This is the example say..:
    Enter First Name: Enter Last Name:
    Enter Age: Enter Address: ..those are the
    data needed for input values...my question now is how can I make a database whi....
  9. How Do I Get The Result To "stick" And Add Html Tags?
    Help please? (14)
    $changepage = $_REQUEST ; echo " $changepage "; ?> Okay, I need a way for any
    information typed in my textarea to "stick" on the page in which it "posts". Since I am creating a
    way for my registered users to decorate their "homepages". So any help, tutorials, etc. would be
    greatly appreciated. ^^ Thanks.....
  10. Php Code Needed Iii
    (10)
    Hello, everyone. I need your help again! Who might create the PHP code, the picture is above
    this text. Basically, I want when the user fill in all the information in this form, it
    automatically was sent to my email. And, then, the dialog box appears or on the same window, it was
    said that your request has been sent. Moreover, if the user did not fill the entire information,
    the dialog box appears stating that you did not fill some field. Thanks, for help. You always do
    that.....
  11. Php Code?
    Mathematical Applications (12)
    Hello, everyone. The help is needed again. How can I make calculator in PHP language? That will act
    like that a user just type in the fields known values, then click the button, and it's going to
    be solved automatically. In other words, have can I write a formula in PHP, how to plug it inside
    that language. For example, the formula to find a peremeter of square is: P=4a. So, a user
    just can write the known value which is peremeter itself and it will find the side of a square; and
    vice versa. If you can write many things how to do such formulas, such as comp....
  12. Php Code Needed
    Working Together? (5)
    Hello, everyone. I need your help again. This forum is quite good for it. Well, I need create a
    registration form for my web-site using PHP and SQL. The information it should contain: 1) User
    Name 2) First Name 3) Last Name 4) Password 5) e-mail Address 6) Security Image: that images helps
    to protect a random registration, for instance, 56+2=where user have to type an answer in order to
    finish registration. That's all for today. Anymore things, I will post another post over here.
    ....
  13. Php Code
    Needed?! (15)
    Well, I am a novice in PHP programming, so there is a script which I wanna get: 1. You go the
    web-site 2. On the main screen, there is a some kind of field windows, the one you get used to type
    in, when you go to google, for instance. 3. He or she types her email address and it's going to
    be saved in my SQL database. 4. That's it. Help me if you can.....
  14. Use Rss In Php Code
    (3)
    so, how can I make RSS reader on my website? thanks in advance....
  15. Will This Code Work
    php linking script ?p= (5)
    hi i'm not that great at php so i'm not to sure if this will work or not. but what i want to
    do is be able to use ?p=staff or what ever page name, with out the php extion, and i would like to
    no if this simple script i made would work. the code is: CODE $p = $_GET ; if ( !empty($p) &&
    file_exists('./' . $p . '.php') && stristr( $p, '.' ) == False ) { // pages
    = directory where you store your pages    $file = './' . $p . '.php'; } else { //
    1.php =  defult page    $file = './index.php'; } include $file; ?> ....
  16. File Checker-how To Check File Whith Html Through Html?
    (2)
    edit:sorry for the mistake it is php not html and its with not whith my code checking script= CODE
    $file = '$CHECK'; if (file_exists($file)) {     echo "The file $filename exists"; } else
    {     echo "The file $filename does not exist"; } ?> my question is how to check the file whith
    html example:on a page a text box is provided and a button the user writes a file name (or website)
    the user clicks on the submit button then it checks and show it (with the code above) i got the
    code CODE $filename=$_POST ; if (file_exists($filename)) {     echo "The....
  17. I Need Some Proof Reading For My Code Please! [resolved]
    (7)
    Well... everything is fine except the Content Select section (refer to the in-code headings)...
    thats where it says the error is... could anyone find out why it wont work when I click one of my
    links? http://2kart.trap17.com/progress.php for an example of what happens...
    //----------------- //portfolio paths //----------------- $portfolio = "/portfolio"; $lay =
    "/images"; //------------------ //navigation //------------------ $link = ·   Home html; $link
    = ·   Portfolio html; $link = ·   Programming html; $link = ·   Graphics html; $link
    = ....
  18. Html Code Tester. Online Script
    (15)
    Yes, yes. I have another script that I have written and I am distributing. I am not entirely sure if
    this works. I have not tested it yet, but I will later and post back with a demo and fix it up.
    Current script: CODE //Save this as something like htmltest.php function CheckForm() {
    $html_unsafe=$_POST ; //Gives us our user input $html_safe=str_replace(" //Starts security measures
    $html_safe=str_replace("?>"," ",$html_safe); //User input now secure server side //Still security
    issues client side echo $html_safe; //echos our statement } //End function //Main script....
  19. Awesome Source Code Viewer Script
    (7)
    Hello! I have just came up with a sweet script to show the source code of any website and it only
    requires one file. This is the basis of the script and can be customized with CSS and other things
    and can be instituted as a public resource. Well I will provide the code and a step-by-step tutorial
    on each of its parts. This code has been tested by me. Enjoy! CODE //This little tag starts
    our php script and is easily the most important part of the script. //We will start our base script
    here. //You can change some of the styles used here to your desired color. if (....
  20. New Found Php Coding Errors
    I always thought these worked, but suddenly they no longer do?! (5)
    Hi i'm dan from new zealand, right next to my home land australia. I have been writing php
    scripts for two years now and just recently none of them have been working. Please help me out as
    best as you can, i'm sure it is only something simple. CODE ----------------Form
    1-------------------------- // ---- Customized form script for the HBRC--------------- //
    Receiving variables ----------------------------------- @$fn = addslashes($_POST ); @$ln =
    addslashes($_POST ); @$f1 = addslashes($_POST ); @$f2 = addslashes($_POST ); @$f3 =
    addslashes($_POST ); //--....
  21. Display The Current Date/time
    With a simple PHP code (4)
    Use this code to display the current date and time. CODE   $date = date('l dS \of F Y
    h:i:s A');   echo "$date"; ?> "l" would display the current day of the week such as
    Sunday. d displays the day of the month... such as 1 and S adds the appropriate suffix(st). /of
    simply displays the word "of". F displays the current month with no abbreviations while Y displays
    the four digit year(2007). "h" displays the current hour with leading zeros if necessary(Ex. 06 for
    6 o'clock). "i" displays the minute of the hour with leading zeros if necessary. ....
  22. Wap Source Code Viewer
    Mobile/wap source code viewer page (4)
    This is a source code viewer that will workl on wap/mobile sites but you can easily convert it to
    work on web im sure ;-) CODE header("Content-Type: text/vnd.wap.wml"); echo '
    ';   print " "; if ($url == "") {      echo " Enter url: »View source code ";   }
    if ($url == "$url") {    $udata=@file_get_contents("$url"); $udata = str_replace("$","$$",$udata);
    $udata = str_replace("&","&",$udata); $udata = str_replace("'","'",$udata); $udata =
    str_replace(" $udata = str_replace(">",">",$udata); $udata = str_replace("\"....
  23. Php And Disabling Html Tags
    how can i do this? (11)
    Hello everyone Im TRYING to make a forum and obviously for security i need to disable HTML tags
    being used in posts. i know how to use the str_replace() function but to be honest i think id have
    to do that for every single tag. I also trued using the html CODE stuff tag but i need to
    be able to use the new line tag to make a new line as all the posts are stored as HTML. if this isnt
    clear let me give an example: QUOTE NEW POST PAGE > user makes new post and posts it > PHP
    PROCCESSOR PAGE MAKES HTML FILE > NEW HTML FILE CONTAINING THE POST > user veiws ....
  24. Requesting Auto Generating Id Tag In Php Code
    Php Coding (3)
    Hello...I'm designing a website in PHP where ppl can submit their links for "cool sites".
    Anyway, when somebody submit's a link to a website for example "http://www.google.com" it
    creates an id such as "index.php?id=1134411593". I dont want the links to be converted into
    id's. I want it to remain as "http://www.google.com". I have the following coding on
    ( echo " ). I'm a novice. Please Help!!!! Thanks... Plus I
    also want to add the date on when the link was submitted. Please follow our forum rule by making....
  25. Dynamic Image / Signature Generator
    a simple code to change text on an image (12)
    In search of dynamically changing quote, saying or all other types of text on an image I came across
    a code that I have modified to fit my initial usage. This procedure requires two files and short
    knowledge of PHP. If you are familiar with Trap17's sig rotation code you will understand this
    procedure very fast. Code 1: dynamic_sig.php (you can rename this to index.php and you'll see
    at the end why) Code 2: a simple text file named anything (I will call it name.txt ) Code 1
    CODE header("Content-type: image/png"); $image = imagecreatefrompng("../i....
  26. Adapting Html Code Embed To Work On Phpnuke
    Help With This Html Code Pls (7)
    QUOTE how can get this html code to work on my phpnuke site? what tags would i
    have to enable in the $Allowable HTML part of my config.php file?? Edited topic title. Moved to
    Programming. ....
  27. Change Permission With Php Code
    code to change files' and folders' permissions? (3)
    As everyone know, there two ways (that I can think of) to change files' and directories'
    permissions. One is to change it in your cPanel's Disk Manager and the other is with an FTP
    client that supports chmod. Well, I'm doing something for my site that requires files to have
    full permissions (Execute, Write, and Read on all three groups). At first, I thought that if I made
    the directory 777, then every file created in that directory will be 777 as well. I'm wrong. An
    alternative to doing this is to change each file permission myself, but that would be....
  28. Get Filename Of Referring Url
    php code to get filename of referring URL (9)
    Hey /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> I want to know how
    to get the filename of the referring URL. Look at the following example: Page A which has a URL of
    http://blah.trap17.com/blah/blah1.php redirects the user to Page B which has a URL of
    http://blah.trap17.com/blah/blah2.php . Is there a PHP code that I can put on blah2.php that will
    output blah1.php? I tried _SERVER ; (please note the code may not exactly be correct as I do not
    remember the code /laugh.gif' border='0' style='vertical-align:middle' alt='laugh.gif' />....
  29. Php Clock
    source Code (8)
    Hi Every one i find this code its very easy simple php clock i think you can use it /blink.gif'
    border='0' style='vertical-align:middle' alt='blink.gif' /> CODE // Binary Clock // script
    copyright© 2002 Andreas Tscharnuter // questions? contact: psychodad@psychodad.at ||
    http://www.psychodad.at/clock/ // free to use, copy and modify but leave comments untouched;) //
    just include this file where your binary clock should appear // version 1.2   03 September 2003 //
    below you can change different settings // and remember to drink m000re milk! $size =  "40";  ....
  30. How do you test your php code
    (97)
    We know that php is a server side scripting language. So we will need a server with the php parser
    to parse/test our code. How are you doing that. Do you upload it to a server for testing or did you
    instal php and the server (apache) on your computer (localhost)....

    1. Looking for html, php, coding, read, html, code

Searching Video's for html, php, coding, read, html, code
See Also,
advertisement


Html Within Php Coding - Is there a way to read HTML Code?

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com