473,395 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How can I combine strip_tags and substr ?

I want to strip tags and return the first x characters. Every combo I try fails.

The code below is where I'm at. It works perfectly stripping the tags, it fails when I try to add substr to limit the length. Not that it should matter, but this is within an Oscommerce setup.


Expand|Select|Wrap|Line Numbers
  1. else {
  2.               $lc_text = '&nbsp;<big><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</big></a>&nbsp;<br><br>' . strip_tags($listing['products_description'], '<br>') . '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . '<strong><font color="#36C426">(...more)</font></strong></big></a>' . '&nbsp;';
  3.             }
Any help would be greatly appreciated.

Thanks,
Walter
Jan 24 '10 #1
2 4380
kovik
1,044 Expert 1GB
You are not using substr at all in that code...

However...

Expand|Select|Wrap|Line Numbers
  1. function buildBriefDescription($description, $length = 100) {
  2.     if (strlen($description) > $length) {
  3.         $description = strip_tags($description);
  4.         return substr($description, 0, $length) . '...';
  5.     }
  6.     return $description;
  7. }
Jan 24 '10 #2
Thanks for the reply!

I wasn't using substr, because however I placed it, I broke the code, I needed to know how to place it.

I worked on this for hours before asking, then I found the solution 5 minutes after asking.

I just changed

strip_tags($listing['products_description'], '<br>')

to

substr(strip_tags($listing['products_description'], '<br>'), 0, 100)
Jan 24 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: lawrence | last post by:
I've a template with some PHP code in it. I need to get the names of all the PHP commands, so I can import them and so I can make sure they are officially allowed (for security purposes, users are...
5
by: MuffinMan | last post by:
Hi, I'm trying to add up an integer with the result from substr() like $second_int = substr( .... ) + $int; I know the result from substr() is an integer and so is $int but in the end...
1
by: praba kar | last post by:
Dear All, In Php I can use strip_tags() function to strip out all html tags. I want to know that strip_tags() equivalent function in Python. regards praba ...
1
by: Jim Dawson | last post by:
I was writing a subroutine to extract fields from lines of text when I ran into an issue. I have reproduced this error on Perl 5.8 on AIX, 5.8 on Linux and 5.6 on Windows. ############### CUT...
2
by: lawpoop | last post by:
Hey folks - I'm working on a spellchecking routine. The pspell libraries don't handle punctuation; I have to make a script a little smarter. I'm having a problem popping English posessive...
6
by: sks | last post by:
Hi, Here is a small program that is wrtten to simply use substr. When the second parameter in substr (length of the string to be extracted) is lesser than 0, the output is the entire string (I'm...
4
by: PlayHard | last post by:
I want my output in two columns like this: C_INCIDENT_TYPE \ TOTAL COUNT How do I combine my two queries to get result. First Query SELECT C_INCIDENT_TYPE, COUNT (*)
1
by: Chad | last post by:
I am having a problem with substr() working when I enter the third perimeter. I am working on a price monitoring project that will download data from Amazon.com. After is downloads the page, it...
1
by: Alexio | last post by:
I have two similar function that need to be combined. Individually they both work however combined one over rides the other. The code is attached below and an attachment is included for data...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.