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.
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?
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
Comments on creating a function
Forum Regular
Usergroup: Customer
Joined: Aug 09, 2004
Location: Chile
Total Topics: 172
Total Comments: 462
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
developer
Usergroup: Administrator
Joined: Dec 20, 2001
Location: Diamond Springs, California
Total Topics: 61
Total Comments: 7868
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?
Forum Regular
Usergroup: Customer
Joined: Aug 09, 2004
Location: Chile
Total Topics: 172
Total Comments: 462
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 ?
developer
Usergroup: Administrator
Joined: Dec 20, 2001
Location: Diamond Springs, California
Total Topics: 61
Total Comments: 7868
Tested {FUNC_REPLACEEMAIL[{LINKEMAIL}]} on link details and it works for me. Don't have the field you're using.
Forum Regular
Usergroup: Customer
Joined: Aug 09, 2004
Location: Chile
Total Topics: 172
Total Comments: 462
You are right, it's working.