Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
|
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 29th, 2004, 07:22 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default Writing on html templates using PHP

i need help with this PHP trick:

i've c'in PHP pages that require a single or >1 .html page and write content on it. when u call that .php page, it'll show content-filled .html page in itself. i c markers like _______CON1_____ or ________MENU_____ etc. on these html template pages.

this is good idea2seperate html design from html content.
how PHP writes on that area ( markers ) ?

__________________
`~@#\^%&*/\.<.\/-|+|_!:;..=?>
PHP, SEO | anshul shrivastava | mediasworks.org | FB
 
Old December 2nd, 2004, 12:34 PM
Authorized User
 
Join Date: Dec 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to colin.horne
Default

I personally prefer using this syntax:





And suchlike.

Then to replace those, you can do a very simple str_replace() on the template (although if you're making more advanced websites, this is genually not a good option).

Cheers

--
Please contact me at:
Colin (dot) Horne (at) gmail (dot) com
 
Old December 6th, 2004, 06:25 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

Can someone tell?
How to open a file and seek occurence of "PAGE_NAME" in it and write "P2P_WROX" ib place of "PAGE_NAME". Rest of the content should remain unmodified.

fseek() or fgets() or other trick ? Please help

 
Old December 6th, 2004, 06:34 AM
Authorized User
 
Join Date: Dec 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to colin.horne
Default

Well, here are the functions you'll need:

To "seek" & replace:
  str_replace()
To get the contents of the file:
  file() or
  file_get_contents() if it's supported

To find out more information about those functions, go to www.php.net/<function_name>


Cheers


--
Please contact me at:
Colin (dot) Horne (at) gmail (dot) com
 
Old December 6th, 2004, 06:57 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

u mean:
$handle=fopen("./file.php", w);
$data1=file_get_contents("./file.php");
$data2=str_replace(PAGE_NAME, anshul, $data1);
fwrite($handle, $data2);
fclose($handle);

thanx; this means get full-content, make many changes, and rewrite the file completely.

is this not possible by moving pointer to desired content in a file, write something, move pointer to another desired content, write something, rewind if neccessary, etc.


 
Old December 6th, 2004, 08:35 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

still ur idea is working excellent!
can sometime now put some light on security issues and preventive solution, if any of concern ?
afterall, anonymous user can write into our files with just a mouse-click!


 
Old December 7th, 2004, 11:30 AM
Authorized User
 
Join Date: Dec 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to colin.horne
Default

Hmmm...

What I actually meant was something more like this :P

MyTemplate.html:
<html>
<title></title>
<body></body>
</html>

And then have myscript.php read mytemplate.html, and perhaps get the values out of a database... Possibly...

:-)

--
Please contact me at:
Colin (dot) Horne (at) gmail (dot) com
 
Old December 13th, 2004, 08:49 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

PHP /is/ a template language already. Why would you use some proprietary format when you can simply use variables?

e.g.
<html>
<title>{$title}</title>
<body>{$body}</body>
</html>

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
 
Old December 15th, 2004, 05:30 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

one related question:

if suppose, we have an html template 'public_request.htm'
and a PHP script writes certain things on it based on users request and then redirects header location to it.

so 'public_request.htm' displays different things based on request type. i've doubt if this possible when many simultaneous requests need that one template open -n- write?

 
Old December 15th, 2004, 06:52 AM
Authorized User
 
Join Date: Dec 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to colin.horne
Default

In reply to richard.york's post.

My only worry about doing that is if variables in the template get displayed by accident, for example:

...
<body>
So if $X + $10 = $100, what is $X?
</body>
...

What should obviously have been written was "\$X", but that's easy to forget...

Cheers

--
Please contact me at:
Colin (dot) Horne (at) gmail (dot) com





Similar Threads
Thread Thread Starter Forum Replies Last Post
write HTML into TEXTAREA using PHP anshul PHP How-To 6 March 27th, 2009 12:15 PM
Writing HTML in VB osemollie Pro VB Databases 5 September 11th, 2006 02:01 PM
HTML formatted text via xsl templates? beckfield XSLT 2 February 26th, 2005 01:48 PM
HTML Templates tsimsha HTML Code Clinic 4 November 8th, 2004 06:32 PM
php in html natmaster Beginning PHP 4 August 1st, 2003 02:48 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.