Webmastersite.net
Register Log In

creating a function
to be called from template

Comments on creating a function

peumus
Forum Regular

Usergroup: Customer
Joined: Aug 09, 2004
Location: Chile

Total Topics: 172
Total Comments: 462
peumus
Posted Jan 18, 2007 - 10:19 PM:

Paul,

I'm inserting the following function in commonfuncs.php :

function replaceemail($email_original)
{
if ($email_original)
{
$email_replaced = str_replace('@', '[at]', $email_original);
$email_replaced = str_replace('.', '[dot]', $email_replaced);
return $email_replaced;
}
}

The difficulty arises when I call it from the template as:

{FUNC_REPLACEEMAIL[{LINKEMAIL_COMPANY}]}

The following warning arises:
Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'replaceemail' was given in D:\xampp\htdocs\tests\companies\templatefunctions.php on line 115

What can be the cause of this warning ?

Before this I had this function directly inside the template but when somebody inserts a " character a lot of errors arises because of the broken php code,
so I want to call the function but not have the code inserted in the template.

Best Regards
Paul
developer

Usergroup: Administrator
Joined: Dec 20, 2001
Location: Diamond Springs, California

Total Topics: 61
Total Comments: 7868
Paul
Posted Jan 20, 2007 - 3:40 PM:

Don't put it in commonfuncs.php, use the modifications directory.

Anyhow, one thing I see is that your function wouldn't return if {LINKEMAIL_COMPANY} is blank... though PHP usually seems to handle return-less functions gracefully. The warning suggests that it doesn't recognize replaceemail to be a function... maybe you put it inside another function or something?
peumus
Forum Regular

Usergroup: Customer
Joined: Aug 09, 2004
Location: Chile

Total Topics: 172
Total Comments: 462
peumus
Posted Jan 20, 2007 - 7:15 PM:

I did put the funcion just before the last ?> this at commonfuncs.php

Now I have done the following trial without success,
I have created the subdirectory modifications/
inside it I have saved a file called myfunctions.php
all that this file contains is the following code:

<?php

function replaceemail($email_original)
{
if ($email_original)
{
$email_replaced = str_replace('@', '[at]', $email_original);
$email_replaced = str_replace('.', '[dot]', $email_replaced);
return $email_replaced;
}
}

?>

When calliing it via {FUNC_REPLACEEMAIL[{LINKEMAIL_COMPANY}]}
I'm receiving the same error as previously:

Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'replaceemail' was given in D:\xampp\htdocs\pruebas\wsnlinks_4_0_11_b\templatefunctions.php on line 115

Also I know this email does exists.

Does the file needs to have a special file name ?
Paul
developer

Usergroup: Administrator
Joined: Dec 20, 2001
Location: Diamond Springs, California

Total Topics: 61
Total Comments: 7868
Paul
Posted Jan 21, 2007 - 4:25 AM:

Tested {FUNC_REPLACEEMAIL[{LINKEMAIL}]} on link details and it works for me. Don't have the field you're using.
peumus
Forum Regular

Usergroup: Customer
Joined: Aug 09, 2004
Location: Chile

Total Topics: 172
Total Comments: 462
peumus
Posted Jan 21, 2007 - 7:04 PM:

You are right, it's working.
Search thread for
Download thread as
  • 0/5
  • 1
  • 2
  • 3
  • 4
  • 5



This thread is closed, so you cannot post a reply.