Click to See Complete Forum and Search --> : how to insert the special character <--break--.


bharanikumarphp
07-07-2008, 12:17 PM
Hi dear

How to insert the special character <--break--> after some character count is reach,

when we add the content,

there some restriction,

the content may contain the html tags,and also self closed tags,


one more thing the <--insert --> tag must insert after the close tag only when the count is comeding between the open and close tag,

this is the sample content, what am going to insert

example

<p>Lorem Ipsum is <b>simply dummy text of the printing</b> and typesetting industry.</p><--break--> <p>Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,</p><-=break--> <p> when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p><--break--><table><tr><td> It has survived not only five centuries,</td></tr></table><--break--> but also the leap into electronic typesetting, <p>remaining essentially unchanged. </p><b>It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,</b><p> and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
Why do we use it?<--break-->
<p>
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.</p> <--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',<b> making it 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 uncover many web sites still in their infancy. Various versions have evolved over the years,</b><--break--> sometimes by accident, sometimes on purpose (injected humour and the like)<--break-->.



somethings need to follow in that:

1. assume if the cursor reached the 125 character then put the <--break-->
2. assume if cursor travel in the 100 character on that time between the <p> and </p> 50 character then , put the <--break--> after </p> ...
3.also check the sentense complete with comma or semicolon,or colon or full stop,then only put the <--break-->,


Thanks in advance :eek:

SyCo
07-07-2008, 01:49 PM
I don't really understand wat you're asking as you're rules are not clearly defined enough. eg If you reach 125 words and the 125th word is not a , or . do you want to insert he <--break--. anyway?

This starts looking for a , or . at $startnum and if it hasn't found one by $maxnum will insert the <--break--> anyway.

$words=explode(' ',$string);
echo count($words);

$startnum=100;//set number of words to begin search for , or .
$maxnum=125;// force insert at this point
$i=1;
foreach($words as $word){

$new_words_array[]=$word;
if($i>$startnum){
if(substr($word,-1)=='.' || substr($word,-1)==','){
$new_words_array[]='<--break-->';
$i=1;//reset counter
}
if($i==$maxnum){
$new_words_array[]='<--break-->';
$i=1;//reset counter
}
$i++;
}

$new_string=implode(' ',$new_words_array);

echo $new_string;

I don't understand #2. and again you definitions are unclear about how to deal with how to insert the <--break--> within a <p></p> if it meets or doesn't meet the other conditions.

also in your desired example you are hoping to get HTML like this?
software like Aldus PageMaker including versions of Lorem Ipsum.</p>
Why do we use it?<--break-->
<p>
It is a long established fact

With 'Why do we use it?<--break-->' outside any <p> tags at all? That seems a bit odd. How does that ft into your other conditions?

You need to define your rules in plain English to be sure of your logic, then you can think of how to convert that to code.

I hope this give an idea. The function preg_match_all() might be useful in working this out.

bharanikumarphp
07-07-2008, 02:14 PM
am basically working in drupal cms,
for article content pagination, am using the paging module,
for that i have to insert the <--break--> with in a content,
so that am expecting this sort function,

and another thing is my content contain html tag,

assume i given the character count is 250,

then after 250i have to insert the <--break--> tag,

assum if the html tag is opned but its not closed upto 240 character reached then only html tag is closed, then insert the <--break-->,

if u insert the beteen the
wrong output

<p>fasdfasfads<--break-->fsadfasfa</p> then it broke the html tag ...

for that i want to insert <--break--> ,, after character count is reached..
this is my expected output


<p>fasdfasfadsfsadfasfa</p> <--break-->

SyCo
07-07-2008, 02:22 PM
So you could use the script i posted to insert all the <--break--> tags then use preg_match_all() to look inside the $new_string for <p></p> tags to see is a <--break--> has been inserted. If it has replace it with nothing eg '' deleting it and replace the closing </p> with </p><--break-->. That would move any <--break--> outside the P tags.

bharanikumarphp
07-07-2008, 02:28 PM
in which place i erite this function
preg_match_all()

dear i written one function,

that work some what fine .. but not exact output is giving...

shall i attache...plz walk through the code

bharanikumarphp
07-07-2008, 03:41 PM
dear why no reply dear

SyCo
07-14-2008, 08:11 PM
No reply because I have job and help out here when I can. I also have a life beyond these boards and sometime go outside, sometimes.

What you want to do is fairly advanced, you might want to go through some tutorials and get a basic grasp of PHP. Your other option is to hire a freelance coder.

bharanikumarphp
07-14-2008, 11:29 PM
Ok fine ,


i found the solution,

u continue dear,