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.

Recommended Answers

$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);
Jump to Post

All 2 Replies

Member Avatar
$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 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.