» Quick Links
You can make money on these forums
We Share profits with you
Google
Google Adsense
Google Adwords
YPN
Yahoo
MSN Search
Web Directories
Web Hosting
Web Hosting Offers
Hosting News
Suggestions
Link Building
Domain Names
PHP Forums
MySQL Forums
» More Links
OSP News
Reseller Hosting
Shared Hosting
Dedicated Servers
Google Adsense
Search Engine Marketing
Link Development
Affiliate Marketing


» Advertising
Multiple DC PR Check

Free SEO Tools


Go Back   Webmaster Forums > Website Developement / Programming > PHP Programming and Tips

PHP Programming and Tips Discuss about PHP programming and Share Tips. Ask questions about Scripting and Errors.

Reply
 
Thread Tools Display Modes
  #1  
Old 09-13-2006, 12:43 PM
design design is offline
OSP Starters
 
Join Date: Aug 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
design is on a distinguished road
Default \r\n inside <p></p> tags. Removel ?

Hello folks,
could anybody help me with the following:
<p>lets say we have
a paragraph like this
that is displayed on multiple lines.</p>
All lines are ended with a \r\n
what I want to do is transform this result (but only within the <p> tags!)so everything is displayed in one line. (not in the browser window, but in the source code), eg:
Using the example above this would result in:
<p>lets say we have a paragraph like this that is displayed on multiple lines</p>
I'm not very good with Regexes, so if anybody can help me this,
it would be highly appreciated.
thanks
bye -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Revenue Sharing Ads ( ?):
  #2  
Old 09-13-2006, 12:49 PM
junik junik is offline
OSP Starters
 
Join Date: Aug 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
junik is on a distinguished road
Default

if you have the <p> area separated out, you can use str_replace quite successfully. if the <p> is located inside a huge block of html and you only want to remove newlines from inside the <p></p> and not outside it, then you're going to have to either separate it out or run a regular expression on the whole mess. You may have to break down and actually learn regex. -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
  #3  
Old 09-13-2006, 12:55 PM
perxy perxy is offline
OSP Starters
 
Join Date: Aug 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
perxy is on a distinguished road
Default

thanks for the quick reply. I know in which direction to look for, and I have experience with regexes. Although I haven't found a solution for this particular issue
the p tag is indeed inside a huge block of other markup language, so that's what makes the reges a little h -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
  #4  
Old 09-13-2006, 01:08 PM
browny browny is offline
OSP Starters
 
Join Date: Aug 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
browny is on a distinguished road
Default

preg_replace_callback
use regex to get whats in the tags, then in the callback use more regex to replace the \r\n's -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
  #5  
Old 09-13-2006, 01:13 PM
quasi quasi is offline
OSP Starters
 
Join Date: Aug 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
quasi is on a distinguished road
Default

I agree with browny
and, since you can't nest p tags... you just need to make sure your regex is "ungreedy" by using a U modifier.
I can't remember if < and > are special in regex, so one of the following should work...
Code:
$pattern = '/\<p\>(.+)\<\/p\>/isU';
//or
$pattern = '/<p>(.+)<\/p>/isU'; -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
  #6  
Old 09-13-2006, 01:24 PM
design design is offline
OSP Starters
 
Join Date: Aug 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
design is on a distinguished road
Default

the problem is matching the data between the p tags, the regexes above won't match it, unless its on the same line.

for instance:
Code:
<p>
test
</p>

would not pass the regex, because it contains \r\n's -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
  #7  
Old 09-13-2006, 01:29 PM
ABRAHM ABRAHM is offline
OSP Starters
 
Join Date: Aug 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
ABRAHM is on a distinguished road
Default

add the m multiline operator

PHP Code:
$pattern = '/\<p\>(.+)\<\/p\>/misU'; -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
  #8  
Old 09-13-2006, 01:37 PM
lance lance is offline
OSP Starters
 
Join Date: Apr 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
lance is on a distinguished road
Default

Quote:
Originally Posted by design View Post
the problem is matching the data between the p tags, the regexes above won't match it, unless its on the same line.

for instance:
Code:
<p>
test
</p>

would not pass the regex, because it contains \r\n's
Actually it will match. try the following example:
PHP Code:
<?php
$txt=<<<FILECONTENTS
<p>
-- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
  #9  
Old 09-13-2006, 01:44 PM
emily emily is offline
OSP Starters
 
Join Date: Apr 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
emily is on a distinguished road
Default

that's right, the m modifier is for the ^ start of text matching and not newline matching. Ignore what i said before. -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Search Engine optimization- HTML TAGS ishan Premium Webmaster Articles 3 09-18-2008 09:28 AM
SEO -Spamming Methods ishan Premium Webmaster Articles 0 02-14-2007 02:30 PM
something about meta tags joe MSN 5 09-26-2006 05:00 AM
google count meta tags? menace Google 7 08-08-2006 11:23 AM
google read old browser tags? binladen Google 4 04-04-2006 12:07 PM


All times are GMT. The time now is 09:03 AM.