 |
| 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
|
|
|
|

November 29th, 2004, 07:22 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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 ) ?
|
|

December 2nd, 2004, 12:34 PM
|
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

December 6th, 2004, 06:25 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

December 6th, 2004, 06:34 AM
|
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

December 6th, 2004, 06:57 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

December 6th, 2004, 08:35 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!
|
|

December 7th, 2004, 11:30 AM
|
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

December 15th, 2004, 05:30 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|

December 15th, 2004, 06:52 AM
|
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|
 |