|
View:
New views
13 Messages
—
Rating Filter:
Alert me
|
|
|
Using eval within Wordpress for a function mixed with htmlHi
I want to evaluate the string below within myfunc() and return a result ready to drop into my home page (echo $s;) For reasons I won't bore you with I want to store this fragment in a text file. Have bashed my head with all sorts of variants, but cannot get eval() to work! The bit that works directly in a page is this: '<a rel="external nofollow" href="'.get_bloginfo('wpurl').'/juniors/mirror"><img src="/oldsite/images/junior/.thumbs/.mirror.jpg" alt="mirror.jpg" title="mirror.jpg" width="95%" /></a> <hr />'; How to use eval() to get the proper result from this type of thing: Assuming I read the above fragment from a text file into variable $s function myfunc($s) eval('\$theresult= \$s;') return $s; So any help would be MUCH appreciated! Best regards from the UK! Chris -- ********************************************************************** Chris Hearn *Tel:* 01625 827589 *Mob:* 07768 725141 *email:* chris.hearn01@... ********************************************************************** The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer. ********************************************************************** _______________________________________________ wp-hackers mailing list wp-hackers@... http://lists.automattic.com/mailman/listinfo/wp-hackers |
|
|
Re: Using eval within Wordpress for a function mixed with htmlI've never tried this myself, but what's jumping out at me is that
you're not using <?php .... ?> in that text... On Mon, Dec 1, 2008 at 4:58 PM, Chris <chris.hearn01@...> wrote: > Hi > I want to evaluate the string below within myfunc() and return a result > ready to drop into my home page (echo $s;) > > For reasons I won't bore you with I want to store this fragment in a text > file. > Have bashed my head with all sorts of variants, but cannot get eval() to > work! > > The bit that works directly in a page is this: > '<a rel="external nofollow" > href="'.get_bloginfo('wpurl').'/juniors/mirror"><img > src="/oldsite/images/junior/.thumbs/.mirror.jpg" alt="mirror.jpg" > title="mirror.jpg" width="95%" /></a> <hr />'; > > How to use eval() to get the proper result from this type of thing: > Assuming I read the above fragment from a text file into variable $s > > function myfunc($s) > eval('\$theresult= \$s;') > return $s; > > So any help would be MUCH appreciated! > > Best regards from the UK! > Chris > > > -- > > ********************************************************************** > Chris Hearn *Tel:* 01625 827589 *Mob:* 07768 725141 *email:* > chris.hearn01@... > ********************************************************************** The > information transmitted is intended only for the person or entity to which > it is addressed and may contain confidential and/or privileged material. > Any review, retransmission, dissemination or other use of, or taking of > any action in reliance upon, this information by persons or entities other > than the intended recipient is prohibited. If you received this in error, > please contact the sender and delete the material from any computer. > ********************************************************************** > _______________________________________________ > wp-hackers mailing list > wp-hackers@... > http://lists.automattic.com/mailman/listinfo/wp-hackers > wp-hackers mailing list wp-hackers@... http://lists.automattic.com/mailman/listinfo/wp-hackers |
|
|
Re: Using eval within Wordpress for a function mixed with htmlOn Mon, Dec 1, 2008 at 3:58 PM, Chris <chris.hearn01@...> wrote:
> How to use eval() to get the proper result from this type of thing: > Assuming I read the above fragment from a text file into variable $s > > function myfunc($s) > eval('\$theresult= \$s;') > return $s; Shouldn't you be returning $theresult? -Otto _______________________________________________ wp-hackers mailing list wp-hackers@... http://lists.automattic.com/mailman/listinfo/wp-hackers |
|
|
Re: Using eval within Wordpress for a function mixed with htmlTrue - I just quoted what I want as a final evaluated result. eval
assumes the string is php code, and html can be added by dropping out of php , like $s= 'echo "hello";?> html here '; eval($s) but it doesn't like function bloginfo('wpurl') and doesnt like angle brackets in the html much either. Chris Daniel Torreblanca wrote: > I've never tried this myself, but what's jumping out at me is that > you're not using <?php .... ?> in that text... > > On Mon, Dec 1, 2008 at 4:58 PM, Chris <chris.hearn01@...> wrote: > >> Hi >> I want to evaluate the string below within myfunc() and return a result >> ready to drop into my home page (echo $s;) >> >> For reasons I won't bore you with I want to store this fragment in a text >> file. >> Have bashed my head with all sorts of variants, but cannot get eval() to >> work! >> >> The bit that works directly in a page is this: >> '<a rel="external nofollow" >> href="'.get_bloginfo('wpurl').'/juniors/mirror"><img >> src="/oldsite/images/junior/.thumbs/.mirror.jpg" alt="mirror.jpg" >> title="mirror.jpg" width="95%" /></a> <hr />'; >> >> How to use eval() to get the proper result from this type of thing: >> Assuming I read the above fragment from a text file into variable $s >> >> function myfunc($s) >> eval('\$theresult= \$s;') >> return $s; >> >> So any help would be MUCH appreciated! >> >> Best regards from the UK! >> Chris >> >> >> -- >> >> ********************************************************************** >> Chris Hearn *Tel:* 01625 827589 *Mob:* 07768 725141 *email:* >> chris.hearn01@... >> ********************************************************************** The >> information transmitted is intended only for the person or entity to which >> it is addressed and may contain confidential and/or privileged material. >> Any review, retransmission, dissemination or other use of, or taking of >> any action in reliance upon, this information by persons or entities other >> than the intended recipient is prohibited. If you received this in error, >> please contact the sender and delete the material from any computer. >> ********************************************************************** >> _______________________________________________ >> wp-hackers mailing list >> wp-hackers@... >> http://lists.automattic.com/mailman/listinfo/wp-hackers >> >> > _______________________________________________ > wp-hackers mailing list > wp-hackers@... > http://lists.automattic.com/mailman/listinfo/wp-hackers > > wp-hackers mailing list wp-hackers@... http://lists.automattic.com/mailman/listinfo/wp-hackers |
|
|
Re: Using eval within Wordpress for a function mixed with htmlYes, quite right Otto,
I simplified it for the post and inadvertantly altered it in theprocess - I am indeed returning $theresult in the actual code I am trying out. The key thing is how to eval() a mixture of php and html to get same result as if it was put straight into a php page. I saw on php lots of discussion of eval(), and different ideas, but also comments that none of them worked properly, so thought would ask on the hackers list. just to re-iterate: this following type of code works straight in a page, <a rel="external nofollow" href="'.get_bloginfo('wpurl').'/juniors/mirror"><img src="/oldsite/images/junior/.thumbs/.mirror.jpg" alt="mirror.jpg" title="mirror.jpg" width="95%" /></a> <hr /> so what should it be so that I can pull it in from a text file, or a database, and then eval() it will give same result? Thanks Chris Otto wrote: > On Mon, Dec 1, 2008 at 3:58 PM, Chris <chris.hearn01@...> wrote: > >> How to use eval() to get the proper result from this type of thing: >> Assuming I read the above fragment from a text file into variable $s >> >> function myfunc($s) >> eval('\$theresult= \$s;') >> return $s; >> > > Shouldn't you be returning $theresult? > > -Otto > _______________________________________________ > wp-hackers mailing list > wp-hackers@... > http://lists.automattic.com/mailman/listinfo/wp-hackers > > wp-hackers mailing list wp-hackers@... http://lists.automattic.com/mailman/listinfo/wp-hackers |
|
|
Re: Using eval within Wordpress for a function mixed with htmlWhy don't you just use sprintf?
$string = '<a rel="external nofollow" href="%s/juniors/mirror"><img src="/oldsite/images/junior/.thumbs/.mirror.jpg" alt="mirror.jpg" title="mirror.jpg" width="95%" /></a> <hr />'; $string = sprintf($string, get_bloginfo('wpurl')); Done! Chris wrote: > Yes, quite right Otto, > I simplified it for the post and inadvertantly altered it in > theprocess - I am indeed returning $theresult in the actual code I am > trying out. > > The key thing is how to eval() a mixture of php and html to get same > result as if it was put straight into a php page. > I saw on php lots of discussion of eval(), and different ideas, but > also comments that none of them worked properly, so thought would ask > on the hackers list. > > just to re-iterate: this following type of code works straight in a page, > <a rel="external nofollow" > href="'.get_bloginfo('wpurl').'/juniors/mirror"><img > src="/oldsite/images/junior/.thumbs/.mirror.jpg" alt="mirror.jpg" > title="mirror.jpg" width="95%" /></a> <hr /> > > so what should it be so that I can pull it in from a text file, or a > database, and then eval() it will give same result? > Thanks > Chris > > Otto wrote: >> On Mon, Dec 1, 2008 at 3:58 PM, Chris <chris.hearn01@...> >> wrote: >> >>> How to use eval() to get the proper result from this type of thing: >>> Assuming I read the above fragment from a text file into variable $s >>> >>> function myfunc($s) >>> eval('\$theresult= \$s;') >>> return $s; >>> >> >> Shouldn't you be returning $theresult? >> >> -Otto >> _______________________________________________ >> wp-hackers mailing list >> wp-hackers@... >> http://lists.automattic.com/mailman/listinfo/wp-hackers >> >> > _______________________________________________ > wp-hackers mailing list > wp-hackers@... > http://lists.automattic.com/mailman/listinfo/wp-hackers _______________________________________________ wp-hackers mailing list wp-hackers@... http://lists.automattic.com/mailman/listinfo/wp-hackers |
|
|
Re: Using eval within Wordpress for a function mixed with htmlgood point on sprintf() - but assumes that I know the link will always
have the bloginfo() as the variable. I was trying to generalise it so that, for several records in a text file, it would do the whole thing! Thanks for suggestion Does anyone know hwo to combine php functions and html using eval?? I would still like to know. Chris Jason Webster wrote: > Why don't you just use sprintf? > > $string = '<a rel="external nofollow" href="%s/juniors/mirror"><img > src="/oldsite/images/junior/.thumbs/.mirror.jpg" alt="mirror.jpg" > title="mirror.jpg" width="95%" /></a> <hr />'; > > $string = sprintf($string, get_bloginfo('wpurl')); > > Done! > > > > Chris wrote: >> Yes, quite right Otto, >> I simplified it for the post and inadvertantly altered it in >> theprocess - I am indeed returning $theresult in the actual code I am >> trying out. >> >> The key thing is how to eval() a mixture of php and html to get same >> result as if it was put straight into a php page. >> I saw on php lots of discussion of eval(), and different ideas, but >> also comments that none of them worked properly, so thought would ask >> on the hackers list. >> >> just to re-iterate: this following type of code works straight in a >> page, >> <a rel="external nofollow" >> href="'.get_bloginfo('wpurl').'/juniors/mirror"><img >> src="/oldsite/images/junior/.thumbs/.mirror.jpg" alt="mirror.jpg" >> title="mirror.jpg" width="95%" /></a> <hr /> >> >> so what should it be so that I can pull it in from a text file, or a >> database, and then eval() it will give same result? >> Thanks >> Chris >> >> Otto wrote: >>> On Mon, Dec 1, 2008 at 3:58 PM, Chris <chris.hearn01@...> >>> wrote: >>> >>>> How to use eval() to get the proper result from this type of thing: >>>> Assuming I read the above fragment from a text file into variable $s >>>> >>>> function myfunc($s) >>>> eval('\$theresult= \$s;') >>>> return $s; >>>> >>> >>> Shouldn't you be returning $theresult? >>> >>> -Otto >>> _______________________________________________ >>> wp-hackers mailing list >>> wp-hackers@... >>> http://lists.automattic.com/mailman/listinfo/wp-hackers >>> >>> >> _______________________________________________ >> wp-hackers mailing list >> wp-hackers@... >> http://lists.automattic.com/mailman/listinfo/wp-hackers > > _______________________________________________ > wp-hackers mailing list > wp-hackers@... > http://lists.automattic.com/mailman/listinfo/wp-hackers > wp-hackers mailing list wp-hackers@... http://lists.automattic.com/mailman/listinfo/wp-hackers |
|
|
Re: Using eval within Wordpress for a function mixed with htmlNot having tested it, But going off what you originally posted:
function getStringFromFile($file) { $s = file_get_contents($file); eval('return ' . $s); } You need to combine the strings, not to insert one string inside the other i believe. On Tue, 02 Dec 2008 11:25:10 +1100, Chris <chris.hearn01@...> wrote: > good point on sprintf() - but assumes that I know the link will always > have the bloginfo() as the variable. > I was trying to generalise it so that, for several records in a text > file, it would do the whole thing! > Thanks for suggestion > Does anyone know hwo to combine php functions and html using eval?? I > would still like to know. > Chris > > > > > Jason Webster wrote: >> Why don't you just use sprintf? >> >> $string = '<a rel="external nofollow" href="%s/juniors/mirror"><img >> src="/oldsite/images/junior/.thumbs/.mirror.jpg" alt="mirror.jpg" >> title="mirror.jpg" width="95%" /></a> <hr />'; >> >> $string = sprintf($string, get_bloginfo('wpurl')); >> >> Done! >> >> >> >> Chris wrote: >>> Yes, quite right Otto, >>> I simplified it for the post and inadvertantly altered it in >>> theprocess - I am indeed returning $theresult in the actual code I am >>> trying out. >>> >>> The key thing is how to eval() a mixture of php and html to get same >>> result as if it was put straight into a php page. >>> I saw on php lots of discussion of eval(), and different ideas, but >>> also comments that none of them worked properly, so thought would ask >>> on the hackers list. >>> >>> just to re-iterate: this following type of code works straight in a >>> page, >>> <a rel="external nofollow" >>> href="'.get_bloginfo('wpurl').'/juniors/mirror"><img >>> src="/oldsite/images/junior/.thumbs/.mirror.jpg" alt="mirror.jpg" >>> title="mirror.jpg" width="95%" /></a> <hr /> >>> >>> so what should it be so that I can pull it in from a text file, or a >>> database, and then eval() it will give same result? >>> Thanks >>> Chris >>> >>> Otto wrote: >>>> On Mon, Dec 1, 2008 at 3:58 PM, Chris <chris.hearn01@...> >>>> wrote: >>>> >>>>> How to use eval() to get the proper result from this type of thing: >>>>> Assuming I read the above fragment from a text file into variable $s >>>>> >>>>> function myfunc($s) >>>>> eval('\$theresult= \$s;') >>>>> return $s; >>>>> >>>> >>>> Shouldn't you be returning $theresult? >>>> >>>> -Otto >>>> _______________________________________________ >>>> wp-hackers mailing list >>>> wp-hackers@... >>>> http://lists.automattic.com/mailman/listinfo/wp-hackers >>>> >>>> >>> _______________________________________________ >>> wp-hackers mailing list >>> wp-hackers@... >>> http://lists.automattic.com/mailman/listinfo/wp-hackers >> >> _______________________________________________ >> wp-hackers mailing list >> wp-hackers@... >> http://lists.automattic.com/mailman/listinfo/wp-hackers >> > _______________________________________________ > wp-hackers mailing list > wp-hackers@... > http://lists.automattic.com/mailman/listinfo/wp-hackers > _______________________________________________ wp-hackers mailing list wp-hackers@... http://lists.automattic.com/mailman/listinfo/wp-hackers |
|
|
Re: Using eval within Wordpress for a function mixed with htmloops, Heres a tested version:
function getStringFromFile($file) { $s = file_get_contents($file); eval('$return = ' . $s . ';'); return $return; } --- Not having tested it, But going off what you originally posted: function getStringFromFile($file) { $s = file_get_contents($file); eval('return ' . $s); } You need to combine the strings, not to insert one string inside the other i believe. On Tue, 02 Dec 2008 11:25:10 +1100, Chris <chris.hearn01@...> wrote: > good point on sprintf() - but assumes that I know the link will always > have the bloginfo() as the variable. > I was trying to generalise it so that, for several records in a text > file, it would do the whole thing! > Thanks for suggestion > Does anyone know hwo to combine php functions and html using eval?? I > would still like to know. > Chris > > > > > Jason Webster wrote: >> Why don't you just use sprintf? >> >> $string = '<a rel="external nofollow" href="%s/juniors/mirror"><img >> src="/oldsite/images/junior/.thumbs/.mirror.jpg" alt="mirror.jpg" >> title="mirror.jpg" width="95%" /></a> <hr />'; >> >> $string = sprintf($string, get_bloginfo('wpurl')); >> >> Done! >> >> >> >> Chris wrote: >>> Yes, quite right Otto, >>> I simplified it for the post and inadvertantly altered it in >>> theprocess - I am indeed returning $theresult in the actual code I am >>> trying out. >>> >>> The key thing is how to eval() a mixture of php and html to get same >>> result as if it was put straight into a php page. >>> I saw on php lots of discussion of eval(), and different ideas, but >>> also comments that none of them worked properly, so thought would ask >>> on the hackers list. >>> >>> just to re-iterate: this following type of code works straight in a >>> page, >>> <a rel="external nofollow" >>> href="'.get_bloginfo('wpurl').'/juniors/mirror"><img >>> src="/oldsite/images/junior/.thumbs/.mirror.jpg" alt="mirror.jpg" >>> title="mirror.jpg" width="95%" /></a> <hr /> >>> >>> so what should it be so that I can pull it in from a text file, or a >>> database, and then eval() it will give same result? >>> Thanks >>> Chris >>> >>> Otto wrote: >>>> On Mon, Dec 1, 2008 at 3:58 PM, Chris <chris.hearn01@...> >>>> wrote: >>>> >>>>> How to use eval() to get the proper result from this type of thing: >>>>> Assuming I read the above fragment from a text file into variable $s >>>>> >>>>> function myfunc($s) >>>>> eval('\$theresult= \$s;') >>>>> return $s; >>>>> >>>> >>>> Shouldn't you be returning $theresult? >>>> >>>> -Otto >>>> _______________________________________________ >>>> wp-hackers mailing list >>>> wp-hackers@... >>>> http://lists.automattic.com/mailman/listinfo/wp-hackers >>>> >>>> >>> _______________________________________________ >>> wp-hackers mailing list >>> wp-hackers@... >>> http://lists.automattic.com/mailman/listinfo/wp-hackers >> >> _______________________________________________ >> wp-hackers mailing list >> wp-hackers@... >> http://lists.automattic.com/mailman/listinfo/wp-hackers >> > _______________________________________________ > wp-hackers mailing list > wp-hackers@... > http://lists.automattic.com/mailman/listinfo/wp-hackers > wp-hackers mailing list wp-hackers@... http://lists.automattic.com/mailman/listinfo/wp-hackers |
|
|
Re: Using eval within Wordpress for a function mixed with htmlIf you're just going to echo the result in the template, why not just
include() the text file? Alan Sent from my iPhone On 1-Dec-08, at 16:58, Chris <chris.hearn01@...> wrote: > Hi > I want to evaluate the string below within myfunc() and return a > result ready to drop into my home page (echo $s;) > > For reasons I won't bore you with I want to store this fragment in a > text file. > Have bashed my head with all sorts of variants, but cannot get > eval() to work! > > The bit that works directly in a page is this: > '<a rel="external nofollow" href="'.get_bloginfo('wpurl').'/juniors/ > mirror"><img src="/oldsite/images/junior/.thumbs/.mirror.jpg" > alt="mirror.jpg" title="mirror.jpg" width="95%" /></a> <hr />'; > > How to use eval() to get the proper result from this type of thing: > Assuming I read the above fragment from a text file into variable $s > > function myfunc($s) > eval('\$theresult= \$s;') > return $s; > > So any help would be MUCH appreciated! > > Best regards from the UK! > Chris > > > -- > > > *** > *** > **************************************************************** > Chris Hearn *Tel:* 01625 827589 *Mob:* 07768 725141 > *email:* chris.hearn01@... > *** > *** > **************************************************************** > The information transmitted is intended only for the person or > entity to which it is addressed and may contain confidential and/ > or privileged material. Any review, retransmission, dissemination > or other use of, or taking of any action in reliance upon, this > information by persons or entities other than the intended > recipient is prohibited. If you received this in error, please > contact the sender and delete the material from any computer. > ********************************************************************** > _______________________________________________ > wp-hackers mailing list > wp-hackers@... > http://lists.automattic.com/mailman/listinfo/wp-hackers wp-hackers mailing list wp-hackers@... http://lists.automattic.com/mailman/listinfo/wp-hackers |
|
|
Re: Using eval within Wordpress for a function mixed with htmlYou're problem appears to be that you are programming when you should be
developing. Take for example your situation. You want a complex solution to a simple problem. If you were a developer, you would use the simple solution for the simple problem. The simple solution would be one that does not involve eval(). I think that if you gave us more code, we'd be able to get to the root of your problem and fix the cause instead of implementing something to cover it up. Jacob Santos Chris wrote: > Hi > I want to evaluate the string below within myfunc() and return a > result ready to drop into my home page (echo $s;) > > For reasons I won't bore you with I want to store this fragment in a > text file. > Have bashed my head with all sorts of variants, but cannot get eval() > to work! > > The bit that works directly in a page is this: > '<a rel="external nofollow" > href="'.get_bloginfo('wpurl').'/juniors/mirror"><img > src="/oldsite/images/junior/.thumbs/.mirror.jpg" alt="mirror.jpg" > title="mirror.jpg" width="95%" /></a> <hr />'; > > How to use eval() to get the proper result from this type of thing: > Assuming I read the above fragment from a text file into variable $s > > function myfunc($s) > eval('\$theresult= \$s;') > return $s; > > So any help would be MUCH appreciated! > > Best regards from the UK! > Chris > > _______________________________________________ wp-hackers mailing list wp-hackers@... http://lists.automattic.com/mailman/listinfo/wp-hackers |
|
|
Re: Using eval within Wordpress for a function mixed with htmlYeah, I gotta agree with Alan on this one. If you're reading a text
file and then eval()ing it, then that's basically the same as an include. Now, on the other hand, if you're eval()ing because you want the output back as a string, then the short answer is that you can't do that. eval() executes the code, and if that code makes output, then it makes the output. The returned result of the eval() call will be whatever that code in the string does as it's "return" statement. Output != returned data. You'd have to use an output buffer to grab the output from the eval(). ob_start() and such. On Mon, Dec 1, 2008 at 9:44 PM, Alan Castonguay <alan@...> wrote: > If you're just going to echo the result in the template, why not just > include() the text file? _______________________________________________ wp-hackers mailing list wp-hackers@... http://lists.automattic.com/mailman/listinfo/wp-hackers |
|
|
Re: Using eval within Wordpress for a function mixed with htmlCouldn't you just use get_bloginfo(), which returns the result, instead of
echoing it? -- http://scribu.net _______________________________________________ wp-hackers mailing list wp-hackers@... http://lists.automattic.com/mailman/listinfo/wp-hackers |
| Free Forum Powered by Nabble | Forum Help |