By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,614 Members | 1,662 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,614 IT Pros & Developers. It's quick & easy.

calling a function through user input.

P: n/a
Hey guys.
So heres yet another question to a problem where I would have no idea
where to look for the answer for so I turn to you :)

Say my sites administrator wants to write a news update or blog or
whatever. Something like this

"Added a new gallery from my trip to Phuket, enjoy:
[GID=24]
If you liked it tell me."

I want the [GID=24] to get replaced by my galery loading function
(very nifty and handy) so it would turn into something like this

echo "Added a new gallery from my trip to Phuket, enjoy:
".galery($GID)."
If you liked it tell me.";
I chose this [GID=24] because it is similar to burning board code. I
would also like to include a command like [PID=45] witch would run my
picture function.

any ideas what functions I am looking for?

bless

May 4 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On May 4, 12:09 pm, Mohawk Mawk <blessblessbl...@gmail.comwrote:
Hey guys.
So heres yet another question to a problem where I would have no idea
where to look for the answer for so I turn to you :)

Say my sites administrator wants to write a news update or blog or
whatever. Something like this

"Added a new gallery from my trip to Phuket, enjoy:
[GID=24]
If you liked it tell me."

I want the [GID=24] to get replaced by my galery loading function
(very nifty and handy) so it would turn into something like this

echo "Added a new gallery from my trip to Phuket, enjoy:
".galery($GID)."
If you liked it tell me.";

I chose this [GID=24] because it is similar to burning board code. I
would also like to include a command like [PID=45] witch would run my
picture function.

any ideas what functions I am looking for?
preg_replace_callback()

HTH

May 4 '07 #2

P: n/a
"Mohawk Mawk" <bl*************@gmail.comwrote in message
news:11*********************@p77g2000hsh.googlegro ups.com...
Hey guys.
So heres yet another question to a problem where I would have no idea
where to look for the answer for so I turn to you :)

Say my sites administrator wants to write a news update or blog or
whatever. Something like this

"Added a new gallery from my trip to Phuket, enjoy:
[GID=24]
If you liked it tell me."

I want the [GID=24] to get replaced by my galery loading function
(very nifty and handy) so it would turn into something like this

echo "Added a new gallery from my trip to Phuket, enjoy:
".galery($GID)."
If you liked it tell me.";
I chose this [GID=24] because it is similar to burning board code. I
would also like to include a command like [PID=45] witch would run my
picture function.

any ideas what functions I am looking for?
preg_replace_callback()
http://fi2.php.net/manual/en/functio...e-callback.php

example:
preg_replace_callback('/\[GID=([\d]+)\]/', 'galery', $input);

But galery will recieve an array of matches, not just an id, so you'll maybe
need to modify it a bit. Also I haven't tested this at all, the example is
just to illustrate the idea...
--
Ra*********@gmail.com

"Good tea. Nice house." -- Worf
May 4 '07 #3

P: n/a
>But galery will recieve an array of matches, not just an id, so you'll maybe
>need to modify it a bit. Also I haven't tested this at all, the example is
just to illustrate the idea...
thank you very much, I inserted a handling function:
function garray($input){
return gallery($input[1]); /* $input[0] is '[GID=X]' and $input[1]
is 'X' */
}

$news="See my galleries one [GID=1] and two [GID=2]";
echo preg_replace_callback('/\[GID=([\d]+)\]/', 'garray', $news);

it works like a charm, this is the beginning of a whole bunch of new
possibilities for the administrator to write news.
thank you very much

May 4 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.