0

I don't know what it calls technically but here what I am trying achieve where user can insert one define word as a string from form text input than it should replace with defined variable.

Example:

$username = myfunction();

Now I want allow to user to enter one defined word like username in input field which will replace with $username variable.

So I want to use it for like Contact to '.$username.' So user can enter and change $username placement with that string keyword and they can play like $username .'info' etc.

Hope I explained properly and not in funny way.

4
  • @WebnetMobile.com, I will surely do that this weekend. Commented Nov 7, 2012 at 14:47
  • @deceze, I don't know how can I convert string to variable with str_replace as I know that is to replace the string only or can replace variable as well? Commented Nov 7, 2012 at 14:47
  • up vote for hint. Thanks a lot Commented Nov 7, 2012 at 15:03
  • Thanks a lot to who gave negative vote. Commented Nov 7, 2012 at 15:03

1 Answer 1

1

You would need to provide the user with a list of template variables like:

##USERNAME##
##ADDRESS##
etc.

that the user can use freely in the form. Then you can do a simple str_replace (that function takes arrays as arguments) to replace all template variables at once.

Your code would look something like:

$search = array('##USERNAME##', '##ADDRESS##', ...);
$replace = array($username, $address, ...);

$modified_text = str_replace($search, $replace, $original_text);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.