Jump to content

[SOLVED] Problem


shage

Recommended Posts

$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 ()

Link to comment
https://forums.phpfreaks.com/topic/59097-solved-problem/
Share on other sites

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;
?>

Link to comment
https://forums.phpfreaks.com/topic/59097-solved-problem/#findComment-293485
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.