[Solved] chopping of text
Moderator: General Moderators
[Solved] chopping of text
Oke . small question basicly.
If i have like a 30 line text but on the front page i only want to show lets say like 10 % of it and with a link read more ....
How to do that.. do i use a count word function or is there some other fancy way for doing this.
If i have like a 30 line text but on the front page i only want to show lets say like 10 % of it and with a link read more ....
How to do that.. do i use a count word function or is there some other fancy way for doing this.
Last edited by ol4pr0 on Sun Aug 29, 2004 11:28 am, edited 1 time in total.
[quote=feyd]
substr can be used.. unless you don't want to come into the middle of a word
[quote]
I am prolly doing something wrong here. but i am still ending up in the middle of some word
substr can be used.. unless you don't want to come into the middle of a word
[quote]
I am prolly doing something wrong here. but i am still ending up in the middle of some word
Code: Select all
echo substr($string, 0,30);- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
something like this may work (untested)it should grab the last word, if it runs over.. not too sure though.
Code: Select all
<?php
preg_match('#^\s*(.{26,}?)\s*.*$#', $test, $match);
?>
Last edited by feyd on Thu Aug 26, 2004 4:33 pm, edited 1 time in total.
Oke just some stupid text i put in ..
text = Jack went to the store to get himself a large bottle of whiskey
output
text = Jack went to the store to get himself a large bottle of whiskey
Code: Select all
echo substr($file_content, 0,36);Jack went to the store to get himsel
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
<?php
$text = 'Jack went to the store to get himself a large bottle of whiskey';
preg_match('#^\s*(.{26,}?)\s+.*$#', $text, $match);
var_export($match);
?>Code: Select all
array (
0 => 'Jack went to the store to get himself a large bottle of whiskey',
1 => 'Jack went to the store to get',
)There is some problem with this tho..
Well actually now its doing this.
Code: Select all
echo $row['message']; // does echo out the message ( but compleet )
preg_match('#^\s*(.{60,}?)\s+.*$#', $row['message'], $match);
echo '<font size="-1">';
echo($match[1]); // this does nothing var_export($match) prints out Array ( )As you can see the both arrays are the samearray (
0 => 'Usted puede ahora enviar su currículum a nuestra página, de esta manera las Empresas podrán revisar su CV. Pero usted tendrá que esperar hasta que el diseño y codificación de las páginas de la empresa estén listos.
Usted podrá ingresar su CV en nuestra Base de Datos pero todavía no podrá utilizar el Interface Administrativo que es el que le permitirá cambiar datos, fotos en su currículum, ya que aún no está terminado. ',
1 => 'Usted puede ahora enviar su currículum a nuestra página, de esta manera las Empresas podrán revisar su CV. Pero usted tendrá que esperar hasta que el diseño y codificación de las páginas de la empresa estén listos.
Usted podrá ingresar su CV en nuestra Base de Datos pero todavía no podrá utilizar el Interface Administrativo que es el que le permitirá cambiar datos, fotos en su currículum, ya que aún no está terminado.',
)
Last edited by ol4pr0 on Sun Aug 29, 2004 11:15 am, edited 1 time in total.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
you may want to add the 's' modifier into the regex:
Code: Select all
//.........
preg_match('#^\s*(.{60,}?)\s+.*$#s', ...........