FTP Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationFTP Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #16  
Old December 14th, 2003, 07:07 PM
edman007's Avatar
edman007 edman007 is offline
Trapped on the forums...help
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Aug 2003
Location: /Users/edman007
Posts: 4,617 edman007 User rank is Lieutenant General (80000 - 90000 Reputation Level)edman007 User rank is Lieutenant General (80000 - 90000 Reputation Level)edman007 User rank is Lieutenant General (80000 - 90000 Reputation Level)edman007 User rank is Lieutenant General (80000 - 90000 Reputation Level)edman007 User rank is Lieutenant General (80000 - 90000 Reputation Level)edman007 User rank is Lieutenant General (80000 - 90000 Reputation Level)edman007 User rank is Lieutenant General (80000 - 90000 Reputation Level)edman007 User rank is Lieutenant General (80000 - 90000 Reputation Level)edman007 User rank is Lieutenant General (80000 - 90000 Reputation Level)edman007 User rank is Lieutenant General (80000 - 90000 Reputation Level)edman007 User rank is Lieutenant General (80000 - 90000 Reputation Level)edman007 User rank is Lieutenant General (80000 - 90000 Reputation Level)edman007 User rank is Lieutenant General (80000 - 90000 Reputation Level)edman007 User rank is Lieutenant General (80000 - 90000 Reputation Level)edman007 User rank is Lieutenant General (80000 - 90000 Reputation Level)  Folding Points: 68775 Folding Title: Intermediate FolderFolding Points: 68775 Folding Title: Intermediate FolderFolding Points: 68775 Folding Title: Intermediate FolderFolding Points: 68775 Folding Title: Intermediate Folder
Time spent in forums: 1 Month 3 Weeks 3 Days 5 h 4 m 15 sec
Reputation Power: 829
Send a message via AIM to edman007
so dose anyone have any way to reinsert the array of url's back into the html after using preg_match or a way to require that a subpatteren NOT start the url so i can use the preg_replace thing as i did above

Reply With Quote
  #17  
Old December 15th, 2003, 01:25 AM
scoutt's Avatar
scoutt scoutt is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2001
Posts: 645 scoutt Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 16 sec
Reputation Power: 0
if it matches then what is there to replace, if it doesn't match then it should give you a variable at teh end of preg_match_all

preg_match_all('!(<a href=(\'|")?(http|ftp)?(s)?(.*?)(\'|")?>)!is', $file, $matches);

that will contain an array of the values that you have to go though and find the ones you need. then just use it to insert it or whatever you have to do.

Reply With Quote
  #18  
Old December 15th, 2003, 04:03 PM
holroy's Avatar
holroy holroy is offline
A happy helper
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Stavanger, Norway
Posts: 458 holroy User rank is Corporal (100 - 500 Reputation Level)holroy User rank is Corporal (100 - 500 Reputation Level)holroy User rank is Corporal (100 - 500 Reputation Level)holroy User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 6 h 29 m 6 sec
Reputation Power: 7
Okey, dokey, are you ready for some heavy magic? Here goes:
PHP Code:
<?php
$text 
= <<<END_OF_TEST
<p><a href="http.html">Humpty, </a> dumpty sat on a <a style="class" 
href='class.html'>wall, <br />Humpty, dumpty, made a 
<a href="http:fall.html">fall</a>, <br />And all the king horses, and all
the <a href="https://somewhere.com">kings</a> <a href='men.html'>men</a><br />
Could never put Humpty, dumpty, together again.</p>
END_OF_TEST;

$base "http://www.nowhere.com/";
echo 
"<pre>"preg_replace("/</""<"$text). "</pre>";
$text =  preg_replace_callback("/<a([^>])*href=([\\"'])([^\\"']*)2>/Us", 
                       create_function('$match', 
                          'global $base; 
                           if (!preg_match ("
/^(https?|ftp):/", $match[3])) {
                             return "
<a$match[1]href="$base$match[3]\\">";
                           } else {
                             return "
<a$match[1]href="$match[3]\\">";
                           }'), $text);

echo "
<pre>". preg_replace("/</", "<", $text). "</pre>";
?>


This could possibly have been written using only the e-modifier, but once you get used to the idea of introducing a function within the regexp it gives you another park to play in, so to speak. And since I wasn't sure what you wanted to do with those not matching https? or ftp I chose to add a $base to them. Change to whatever you like. But remember to escape any single quotes within the code.

Does this solve your problem?

<e><

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationFTP Help > PCRE--match that don't have http://, https://, or ftp://


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
Stay green...Green IT