| re: insert value with special varible
Just to clarify you want to insert that phrase every 100 characters or every number of words.
Your example shows the <--break--> in between the words and never occurs in the middle of a word.
If that's just a mistake, here's the code to insert every so characters, not words:
[PHP]
<?php
$myString = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum";
$everyNum = 100;
$insert = "<--break-->";
$tempArray = array();
$resultString = "";
$iterator = (int)(strlen($myString)/$everyNum) + (((strlen($myString) % $everyNum) > 0)? 1 : 0);
for($i = 1; $i < $iterator; $i++)
{
$subStr = substr($myString,$i*$everyNum,$everyNum);
array_push($tempArray,$subStr);
}
foreach($tempArray as $str)
{
$resultString .= $str . $insert;
}
echo $resultString;
/* output:
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the <--break-->industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type a<--break-->nd scrambled it to make a type specimen book. It has survived not only five centuries, but also the <--break-->leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s w<--break-->ith the release of Letraset sheets containing Lorem Ipsu
m passages, and more recently with desktop p<--break-->ublishing software like Aldus PageMaker including versions of Lorem Ipsum<--break-->
*/
?>
[/PHP]
I know my calculations of the iterator might be bloated, but I did this real quick. I'm a mechanic in real life and never was that good at math. Any body else care to take over that part?
Dan
|