shage Posted July 9, 2007 Share Posted July 9, 2007 $body=$randbody; $counter=substr_count($body,"("); for($c=0;$c<$counter;$c++) { $splitted=str_split($body); for($i=0;$i<count($splitted);$i++) { if($splitted[$i]=="(") { while($splitted[$i]!=")") { $con.=$splitted[$i]; $i++; } } } $string=$con; $result=explode("(",$string); $values=explode(",",$result[1]); $tot=count($values); $tot-=2; $random=rand(0,$tot); $res=$values[$random]; $body=substr_replace($body,$res,strpos($body,"("),(strpos($body,")")-strpos($body,"(")+1)); } $randbody=stripslashes($body); Explain to me why in the body everywhere i put (whatever,test,random,) is suppose to random the text in the () it does it but it keeps the first () and randoms it everywhere () is located, i want to be able to random () different depending on whats in () Quote Link to comment Share on other sites More sharing options...
sasa Posted July 9, 2007 Share Posted July 9, 2007 is it what you try <?php $body = 'I am (15,23,96) y old and I go to (Paris,Wien,Los Angeles,Rim).'; $body = explode('(', $body); $out = $body[0]; for ($i = 1; $i < count($body); $i++){ $con = explode(')',$body[$i]); $pos = explode(',', $con[0]); $out .= $pos[rand(0, count($pos)-1)]. $con[1]; } echo $out; ?> Quote Link to comment Share on other sites More sharing options...
shage Posted July 9, 2007 Author Share Posted July 9, 2007 THANK YOU!!!!!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.