Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > PHP+MySQL... How to cut off a textstring ?

PHP+MySQL... How to cut off a textstring ?
Thread Tools
Mac Elite
Join Date: Mar 2001
Location: München, Deutschland
Status: Offline
Reply With Quote
Jun 16, 2005, 04:46 PM
 
Hi folks,

I know it's easy, but I am starring too long on it now:

I get data from a MySQL DB here:
// SQl Statement
$query_products = "SELECT ID, HEADLINE, HEAD, TEXT, PIC_PR FROM RS_03_PRODUCTS";
// Query
$localProducts = $db_products->SQLReqNames($query_products);


Here is my output on the webpage:
for ( $count=0; $count<sizeof($localProducts); $count++)
{
?>
<img src="<?=$path_imgdb.$localProducts[$count]['PIC_PR']?>">
<br>
<b><?=$localProducts[$count]['HEADLINE']?></b>
<br>
<b><?=$localProducts[$count]['HEAD']?></b>
<br>
<?=$localProducts[$count]['TEXT']?>
<br>
<?
}


Where/how do I cut off the data from TEXT to, say, 300 characters?

Thanks,
Powerbook
(Last edited by Powerbook; Jun 18, 2005 at 08:33 PM. )
Aut Caesar aut nihil.
     
Registered User
Join Date: Apr 2003
Location: The Internets
Status: Offline
Reply With Quote
Jun 16, 2005, 04:47 PM
 
     
Grizzled Veteran
Join Date: Oct 2003
Status: Offline
Reply With Quote
Jun 17, 2005, 11:37 AM
 
even better use preg_replace to have it chop off at the closest word instead of cutting a word in half:

[php]$char_count = 300;

$text = preg_replace("/(^.{0,$char_count})(\W+.*$)/", "\${1}", $text);[/php]
The only thing necessary for evil to flourish is for good men to do nothing
- Edmund Burke
     
Mac Elite
Join Date: Mar 2001
Location: München, Deutschland
Status: Offline
Reply With Quote
Jun 18, 2005, 08:30 PM
 
That variable problem is solved, or never weas one, but I am not getting any info out of the MySQL db...
Somehow my statement ist correct, but empty.

$query_product_content = "SELECT ID, HEADLINE, HEAD, TEXT, PIC, PRODUCT_ID FROM RS_03_PRODUCTS WHERE PRODUCT_ID="
$query_product_content .= $prod_id;

Hm.........

Regards
Powerbook
(Last edited by Powerbook; Jun 20, 2005 at 11:57 AM. )
Aut Caesar aut nihil.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:16 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2