Tokens with PHP?

aim high

New member
Jun 3, 2008
335
5
0
This is what I want to do.

Have a web page with a paragraph. Lets say

"Hi my name is Bill. blah blah"

but I want to use tokens so its

"Hi my name is {Name}"

where name is like a list of 20 names. Is there a way to draw data from an excel spreadsheet opposed to just having it all in the coding which would get messy? Is there a better solution opposed to php?
 


USe a database or (in your case) an array.

Easy to do, just pick up any PHP tutorial and figure it out.

Why? because you will learn a lot that will help ya later.

::emp::
 
Code:
<?php

$token = '{name}';
$input = "Yadayada blabla $token";
$names = array('Name1', 'Name2', 'Name3');
$name = $names[rand(0, sizeof($names))];
$output = str_replace($token, $name, $input);
echo $output;

?>
 
i just got it done in 4 hours with around 80 separate tokens with arrays haha. probably would have been easier with a little bit more php knowledge. going to pick up a php/sql book now.