php - How do I return the variable from a function? -


i trying return variable function , print out. displaying unexpected t_string right now.... can help?

function reg_word($i){ $reg_word = "/[^a-za-z0-9 ]/"; $i = preg_replace($reg_word, '', $i); } $suggestion = function reg_word($_post['suggestions']); print_r($suggestion); 

function reg_word($i){ $reg_word = "/[^a-za-z0-9 ]/"; return preg_replace($reg_word, '', $i); } $suggestion = reg_word($_post['suggestions']); print_r($suggestion); 

you had function keyword before reg_word($_post['suggestions']); - don't need it. need use return keyword return function.


Comments

Popular posts from this blog

JQuery Autocomplete without using label, value, id -

c++ - Accessing inactive union member and undefined behavior? -

JAVA - what is the difference between void and boolean methods? -