Hi everybody!

I would like to ask for your help if it possible, I have a long sting and I want to chop it to small pieces. My string is:-

$longstr = “Str1.htmlstr2.htmlstr3.html”;

And I want the result to be like;

$firstchoppedpiece = “Str1.html”;

$secondchoppedpiece =”Str2.html”;

$thirdchoppedpiece =”Str2.html”;

Is it possible? Or is there any PHP function or method to break it into small pieace?

Your replies are greatly appreciated.

Thank very much.

Member Avatar for diafol
$str = "Str1.htmlstr2.htmlstr3.html";
$bits = preg_split('/(.html)/', $str, -1, PREG_SPLIT_DELIM_CAPTURE);

$files = array();
for ($i=0, $j=count($bits)-1; $i<$j; $i+=2) $files[] = $bits[$i].$bits[$i+1];
if ($bits[$j] != '') $files[] = $bits[$j];

print_r($files);

Thank you for your time and reply, I do appreciate.
I will check a bit later to see in practice.
Regards bobtutos.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.