ok - please forgive me if i dont make sence - ill try to explain what i want
to do
i have an file that i want to change a few srings in it (its a .htm file)
i use the str_replace funtion to replace the nessasary strings - i then want
to include the result in the php file that is doing the changes.
this is what i have got
MY index.php file is as per below
------------------
<?PHP
$file=implode(" ",file("main.ht ml"));
$file=str_repla ce("$stringToFi nd","$NewString ", $file);
echo $file;
?>
--------------------
but this doesnt parse any php that is in $file
i thought a way around this would be to save $file as say file.tmp and then
use an include statement to include this. then delete file.tmp
is there any other way around it
thanks 8 2157
i have worked it out - i used the output buffering .
"chris" <so*****@here.c om> wrote in message
news:41******** @funnel.arach.n et.au... ok - please forgive me if i dont make sence - ill try to explain what i want to do
i have an file that i want to change a few srings in it (its a .htm file)
i use the str_replace funtion to replace the nessasary strings - i then want to include the result in the php file that is doing the changes.
this is what i have got
MY index.php file is as per below ------------------ <?PHP $file=implode(" ",file("main.ht ml")); $file=str_repla ce("$stringToFi nd","$NewString ", $file); echo $file; ?> --------------------
but this doesnt parse any php that is in $file
i thought a way around this would be to save $file as say file.tmp and then use an include statement to include this. then delete file.tmp
is there any other way around it
thanks
Use eval:
<?PHP
$file=implode(" ",file("main.ht ml"));
$file=str_repla ce("$stringToFi nd","$NewString ", $file);
eval( '?>' . $file . '<?php' );
?>
Hilarion
Hilarion wrote: Use eval:
<?PHP $file=implode(" ",file("main.ht ml")); $file=str_repla ce("$stringToFi nd","$NewString ", $file); eval( '?>' . $file . '<?php' ); ?>
Hilarion
N.B. eval should be avoided at all costs it's "expensive"
Ref: http://uk2.php.net/manual/en/function.eval.php
~Cameron
Nothing "should be avoided at all costs" even if it's expensive. It only has
to be used wisely. (Speed and memory optimization is not the main goal
of every coding.)
Hilarion
PS.: My code should be: eval( '?' . '>' . $file . '<' . '?php ' );
Hilarion wrote: Nothing "should be avoided at all costs" even if it's expensive. It only has to be used wisely. (Speed and memory optimization is not the main goal of every coding.)
In fact you should read "should only be used as a last resort". Fortunate,
the OP did find a better solution using output buffering.
JW
Hilarion wrote: Nothing "should be avoided at all costs" even if it's expensive. It only has to be used wisely. (Speed and memory optimization is not the main goal of every coding.)
Hilarion
PS.: My code should be: eval( '?' . '>' . $file . '<' . '?php ' );
Well ok, I meant unless there is no other solution, just worded it
badly, and one of the comments on the function page contains the quote
"If eval() is the answer, you're almost certainly asking the
wrong question. -- Rasmus Lerdorf, BDFL of PHP"
~Cameron
It's also bad programming, in my experience. I've never seen or even heard
of a good reason for using it, where some extra coding couldn't do the job
much faster. I'm not criticising, just expressing my opinion :)
"Cameron" <ca*@foo.bar.in valid> wrote in message
news:co******** ***********@new s.demon.co.uk.. . Hilarion wrote: Use eval:
<?PHP $file=implode(" ",file("main.ht ml")); $file=str_repla ce("$stringToFi nd","$NewString ", $file); eval( '?>' . $file . '<?php' ); ?>
Hilarion
N.B. eval should be avoided at all costs it's "expensive"
Ref: http://uk2.php.net/manual/en/function.eval.php
~Cameron
Exactly. Thanks Cameron & Rasmus :)
"Cameron" <ca*@foo.bar.in valid> wrote in message
news:co******** ***********@new s.demon.co.uk.. . Hilarion wrote: Nothing "should be avoided at all costs" even if it's expensive. It only has to be used wisely. (Speed and memory optimization is not the main goal of every coding.)
Hilarion
PS.: My code should be: eval( '?' . '>' . $file . '<' . '?php ' );
Well ok, I meant unless there is no other solution, just worded it badly, and one of the comments on the function page contains the quote
"If eval() is the answer, you're almost certainly asking the wrong question. -- Rasmus Lerdorf, BDFL of PHP"
~Cameron This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: fartsniff |
last post by:
i found this code out in the ng, and its seems long and clunky,
i am still experimenting with preg_match and _replace, but the
syntax is a bit confusing. it seems i always misplace or mistype
something.
this is the code that i am trying to replace with better, optimized code.
i would like to make a preg_match and then preg_replace for this, and if
a match is found, just removing it.
i started with this:
|
by: mrquake99 |
last post by:
Hi,
I am looking for php tools / scripts with which I can convert php
generated HTML to PDF. I was looking at FPDF and HTML2PDF (based on
FPDF). However, HTML2PDF can not handle nested lists and the output is
wrong. If I generate a PDF from:
<ul>
<li>L1</li>
<li>L2</li>
|
by: StevePBurgess |
last post by:
With a string of authors such as:
Carson, David, Milne, Rebecca, Pakes, Francis J., Shalev, Karen,
Shawyer, Andrea
I would like to write a function to change every other comma into a
semi colon (thereby defining where one name ends and the next begins).
I could do it by writing a complex (and slow) procedure - but is there
a quick way of doing it using regular expressions, for example?
|
by: comp.lang.tcl |
last post by:
set php {<? print_r("Hello World"); ?>}
puts $php; # PRINTS OUT <? print_r("Hello World"); ?>
puts
When I try this within TCL I get the following error:
|
by: abscons |
last post by:
Hi out there,
I have an url that looks like this: http://host/file?var=value.
I am trying to replace the "value" part in my url and assign it to a
link on my page. I tried to parse the url but can only get the part
before the ? not included.
Is there any way to do so?
Thx.
| |
by: robski |
last post by:
Hello there,
I am new to this forum and have done my best to look around for a solution to this problem.
I am using PHP to generate an HTML Select drop down menu, with 4 options:
function access_full($file, $access_level) {
$template = 'templates/select_tags.tmp';
$select = file_get_contents($template);
$template = 'templates/drop_down_option.tmp';
|
by: Jon Slaughter |
last post by:
Can I modify code that I have included using
<?php
include("../Index.php");
?>
The Index.php file contains links that need to be modified to work.
Index.php is basically an html file uses a linked css file and when its
included in the new file its referencing a css file in the wrong spot. I
need to add "../" to the css file reference in Index.php to make it work.
|
by: Smiley |
last post by:
I'm fooling around with using Eval and trying to manipulate a few things. I
ran into a couple of weird results. First of all, in one place I used the
following code:
$filestring = str_replace("<?", "\n<?\n", $filestring);
$filestring = str_replace("?>", "\n?>\n", $filestring);
Not a huge thing, just making things easier to read for me. But doing this
gives me an error, even when I comment those lines out. I have to remove
them...
|
by: Sean Kim |
last post by:
From example in the book 'Programming PHP' (O'Reilly) (p.305)
$theKey = 'DESTINATION';
$target = '{' . $theKey . '}';
$inValues = 'some.php';
//$theTemplate = str_replace("\{$theKey}", $inValues,
theTemplate);
//$theTemplate = str_replace("{$theKey}", $inValues,
theTemplate);
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |