Hi all!
I really need some help :queasy:
I have these two things:
$string = "blabla<input type='checkbox' value='' name='utakmica'>blaablaablaa<input type='checkbox' value='' name='utakmica'>blaablaablaa<input type='checkbox' value='' name='utakmica'>";
$array = array("b1", "b2", "b3");
What am I trying to do with the code , is to insert in every
value=''
the appropriate value for it. That is the final string I need:
$final_string = "blabla<input type='checkbox' value='b1' name='utakmica'>blaablaablaa<input type='checkbox' value='b2' name='utakmica'>blaablaablaa<input type='checkbox' value='b3' name='utakmica'>";
I tried the code, which worked if the value of the string was "ac ac ac", and instead of
$array_string = explode("' name='utakmica'",$string);
I used
$array_string = explode(" ",$string);
. But when I inserted the actual values I need:
$array = array("b1", "b2", "b3");
$arraysize = sizeof($array);
$string = "blabla<input type='checkbox' value='' name='utakmica'>blaablaablaa<input type='checkbox' value='' name='utakmica'>blaablaablaa<input type='checkbox' value='' name='utakmica'>";
$array_string = explode("' name='utakmica'",$string);
for ($i = 0; $i<$arraysize; $i++) {
$combine_array = "". $array[$i] ."". $array_string[$i] ."";
$final_string = "$final_string ". $combine_array ."";
}
echo $final_string;
what I get was:
b1blabla<input type='checkbox' value=' b2>blaablaablaa<input type='checkbox' value=' b3>blaablaablaa<input type='checkbox' value='
Why is this error happening when I replace "ac ac ac" with more difficult string...? Do you know how can I get the desired stirng:
$final_string = "blabla<input type='checkbox' value='b1' name='utakmica'>blaablaablaa<input type='checkbox' value='b2' name='utakmica'>blaablaablaa<input type='checkbox' value='b3' name='utakmica'>";
,
using just these two things:
$string = "blabla<input type='checkbox' value='' name='utakmica'>blaablaablaa<input type='checkbox' value='' name='utakmica'>blaablaablaa<input type='checkbox' value='' name='utakmica'>";
$array = array("b1", "b2", "b3");