Forum Moderators: coopster

Message Too Old, No Replies

Calling a function from inside a another function

         

wruk999

6:52 pm on Sep 17, 2003 (gmt 0)

10+ Year Member



Hi,
I hope someone here can help me, I have built a PHP CMS/Template site, where all the header, footer and nav bar html is printed in from includes etc. Also, I have a few functions fro printing text (from dbase, as this is also a CMS) and printing code for inserting an image.

The function for printing text, printtext();, through which I pass arguments, works perfectly, and draws the text from the dbase. When the text is added to the dbase, it is converted to include the <br> and <p> tags. thats all works perfect.

What I now need to be able to do, is call a second function, printimage("imagename.jpg", "alignment"); from inside the printed text from the printtext function.

I tried putting just printimage(blah); but it wouldnt have it. I tried putting <? function?> round it...but no joy neither :(

Does any way of how I could acheive this?

Cheers,
wruk999

coopster

7:09 pm on Sep 17, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



As long as it has been defined, you shouldn't have any issues. Any valid PHP code may appear inside a function, even other functions. If the PHP Functions Manual [us4.php.net] doesn't answer your questions, post a snippet of your function call within your function and we'll try to help.

wruk999

7:59 pm on Sep 17, 2003 (gmt 0)

10+ Year Member



Hi coopster,

thanks for the reply. unfortunately, I probably didnt explain myself clear enough.

What it is, is I use a printtext function to grab specific text from a row in a dbase table. It is then returned back to the page, and displys the text into the html.

What I need to do, is at places in the text, put a call to insert an image (using a function, printimage), but I dont want to do this on the page, I want to do this in the dbase, as part of the CMS, so I need to store it in the dbase with the text.

I suppose the only other way of doing it, would be to store something else in the dbase, and do a preg_replace on it before it is outputted to the page. At the moment, this is how it is printing on the page. (This is a view source of the page, after it has been php generated and returned to the browser:


<td colspan="2" class="maintext">Testing Text<br>Another line here<p>And another para</p><?php insertimage("testimage.jpg", "left");?>
<p>&nbsp;</p>

Thats an exact copy of the code from the page. It isnt running the php bit through php parser - well thats what it looks like.

I hope this explains my problem a little clearer :)

Cheers,
wruk999

ergophobe

9:51 pm on Sep 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If I understand, I believe that what you are looking for is the

eval()

function. Put the text from the DB in $var1. Then do
eval($var1);

That will give you the second go round you are looking for if I understand correctly.

Tom