Connecting Tech Pros Worldwide Help | Site Map

insert value with special varible

Newbie
 
Join Date: Jun 2008
Posts: 2
#1: Jun 29 '08
hi dear

i want to insert the special character word <--break--> ,

every 100 character between..

example

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's <--break-->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. <--break-->It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.<--break--> It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently<--break--> with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum


like this.
dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,095
#2: Jun 30 '08

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
Newbie
 
Join Date: Jun 2008
Posts: 2
#3: Jul 1 '08

re: insert value with special varible


Friends

Am inserting the big contents into table,

and i want to add the spcial character in that content, after 200 character hass reached

Example,

It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.<--BREAK--> The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it <--BREAK-->look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will <--BREAK-->uncover

like this manner,,

Any idea for this,

There some string function can do this,

any idea friends
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#4: Jul 1 '08

re: insert value with special varible


You have already posted this exact same question.
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#5: Jul 2 '08

re: insert value with special varible


Heya, bharanikumariyerphp.

Are you looking for wordwrap() (http://php.net/wordwrap)?
Reply