PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Oct 15, 2018 9:08 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Mon Aug 23, 2004 1:43 pm 
Offline
Forum Regular
User avatar

Joined: Thu Jan 08, 2004 12:22 pm
Posts: 926
Location: ecuador
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.


Last edited by ol4pr0 on Sun Aug 29, 2004 11:28 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 23, 2004 2:14 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
substr can be used.. unless you don't want to come into the middle of a word.. preg_replace can be used for extracing the words and stripping/ignoring tags and bbcode


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 23, 2004 4:29 pm 
Offline
Forum Regular
User avatar

Joined: Thu Jan 08, 2004 12:22 pm
Posts: 926
Location: ecuador
thx


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 26, 2004 4:09 pm 
Offline
Forum Regular
User avatar

Joined: Thu Jan 08, 2004 12:22 pm
Posts: 926
Location: ecuador
[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

Syntax: [ Download ] [ Hide ]
echo substr($string, 0,30);


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 26, 2004 4:27 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
something like this may work (untested)
Syntax: [ Download ] [ Hide ]
<?php



preg_match('#^\s*(.{26,}?)\s*.*$#', $test, $match);



?>
it should grab the last word, if it runs over.. not too sure though.


Last edited by feyd on Thu Aug 26, 2004 4:33 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 26, 2004 4:28 pm 
Offline
DevNet Resident
User avatar

Joined: Thu Feb 12, 2004 8:19 pm
Posts: 1165
Location: ohio
i wonder whats wrong with his substr? it looks good to me.

can u echo out the $string and get the text u wish to play with?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 26, 2004 4:33 pm 
Offline
Forum Regular
User avatar

Joined: Thu Jan 08, 2004 12:22 pm
Posts: 926
Location: ecuador
Oke just some stupid text i put in ..

text = Jack went to the store to get himself a large bottle of whiskey

Syntax: [ Download ] [ Hide ]
echo substr($file_content, 0,36);


output

Quote:
Jack went to the store to get himsel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 26, 2004 4:39 pm 
Offline
DevNet Resident
User avatar

Joined: Thu Feb 12, 2004 8:19 pm
Posts: 1165
Location: ohio
yeah its doing the job

0 is where to start, 36 is how many chars over (including white spaces) it will capture.

if u count, himself, the l in that makes for 36 chars

=]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 26, 2004 4:39 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
Syntax: [ Download ] [ Hide ]
<?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);



?>
outputs
Syntax: [ Download ] [ Hide ]
array (
0 => 'Jack went to the store to get himself a large bottle of whiskey',
1 => 'Jack went to the store to get',
)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 26, 2004 4:52 pm 
Offline
Forum Regular
User avatar

Joined: Thu Jan 08, 2004 12:22 pm
Posts: 926
Location: ecuador
Thanks. altho feyd i do not completely understand what u are doing in ure example


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 26, 2004 5:08 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
it grabs a minimum of 26 characters, if the 27th character isn't a space, it continues out until there is a space. Thus, not chopping words in two.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 29, 2004 11:09 am 
Offline
Forum Regular
User avatar

Joined: Thu Jan 08, 2004 12:22 pm
Posts: 926
Location: ecuador
There is some problem with this tho..
Syntax: [ Download ] [ Hide ]
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 ( )


Well actually now its doing this.

Quote:
array (

0 =&gt; '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 =&gt; '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.',

)


As you can see the both arrays are the same


Last edited by ol4pr0 on Sun Aug 29, 2004 11:15 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 29, 2004 11:15 am 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
you may want to add the 's' modifier into the regex:
Syntax: [ Download ] [ Hide ]
//.........

preg_match('#^\s*(.{60,}?)\s+.*$#s', ...........


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 29, 2004 11:19 am 
Offline
Forum Regular
User avatar

Joined: Thu Jan 08, 2004 12:22 pm
Posts: 926
Location: ecuador
that s would stand for space ? i asume


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 29, 2004 11:26 am 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
http://www.php.net/manual/en/reference. ... ifiers.php


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group