PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

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 Codewalkers Forums Sponsor:
  #1  
Old October 22nd, 2009, 01:42 PM
monicka87 monicka87 is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 2 monicka87 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 1 m
Reputation Power: 0
php5 - Hyperlinks creation

Hi

I need some help to get this done using php:


1 - I have few hyperlinks say 500 in format like:

Code:
<a href="(URL address blocked: See forum rules)/1.html" target="_blank">(URL address blocked: See forum rules)/1.html</a>
<a href="(URL address blocked: See forum rules)/1.html" target="_blank">(URL address blocked: See forum rules)/1.html</a>
<a href="(URL address blocked: See forum rules)/21.html" target="_blank">(URL address blocked: See forum rules)/21.html</a>
<a href="(URL address blocked: See forum rules)/new.php" target="_blank">(URL address blocked: See forum rules)/new.php</a>


etc etc

Now I want to convert them into format like:
Code:
<a href="(URL address blocked: See forum rules)/1.html" target="_blank">keyword 1</a>
<a href="(URL address blocked: See forum rules)/1.html" target="_blank">keyword 2</a>
<a href="(URL address blocked: See forum rules)/21.html" target="_blank">keyword 3</a>
<a href="(URL address blocked: See forum rules)/new.php" target="_blank">keyword 4</a>



Here keyword 1,2,3,4 can be taken randomly from a file which has huge list of keywords or may be we can paste the hyperlinks and keywords in php form itself and then it just links into the manner as given above.

Can anyone provide the code for doing this?

Thanks
Monicka

Reply With Quote
  #2  
Old October 22nd, 2009, 02:26 PM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 5 Days 1 h 54 m 18 sec
Reputation Power: 4
you would probably have to use some sort of regular expression to do a search and replace. something like this:

PHP Code:
<?php
//load in the links as a string however you want.
$linksIn =<<<LINKS
<a href="http://www.yoursite.com/1.html" target="_blank">http://www.yoursite.com/1.html</a>
<a href="http://www.yoursite.com/1.html" target="_blank">http://www.yoursite.com/1.html</a>
<a href="http://www.yoursite.com/21.html" target="_blank">http://www.yoursite.com/21.html</a>
<a href="http://www.yoursite.com/new.php" target="_blank">http://www.yoursite.com/new.php</a>
LINKS;
//load in the keywords as an array however you want.
$keywords = array("keyword 1","keyword 2","keyword 3","keyword 4");

//show the before
echo "<h2>Before:</h2><pre>".htmlentities($linksIn)."</pre><hr />";

//get a list of matches for our regex
preg_match_all('/<a[^>]*?>.*?<\/a>/i',$linksIn,$matches);

//loop around through the links.
foreach($matches[0] as $m){
    
//replace link with a random keyword.
    
$r preg_replace('/(<a[^>]*?>)(.*?)(<\/a>)/i''\1'.$keywords[mt_rand(0,count($keywords)-1)].'\3'$m);
    
//replace the link in the main text with the link with the keyword
    
$linksIn preg_replace('/'.preg_quote($m'/').'/'$r$linksIn1);
}
//show the after
echo "<h2>After:</h2><pre>".htmlentities($linksIn)."</pre>";

?>

Reply With Quote
  #3  
Old October 23rd, 2009, 02:57 AM
monicka87 monicka87 is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 2 monicka87 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 1 m
Reputation Power: 0
Thanks.. I am revising my problem and making it more clear and simple now as:

I would need a PHP form page with two form fields:

Form Field A-

In this box we can paste bulk URLS like
Code:
(URL address blocked: See forum rules)/1.html
(URL address blocked: See forum rules)/2.html
(URL address blocked: See forum rules)/my.html
(URL address blocked: See forum rules)/new.html

etc


Form Field B-

In this box we can paste list of keywords like

keyword 1
keyword 2
keyword 3
keyword 4
keyword 5
etc

Lastly there is "SUBMIT" button and when we click on it then it provides us code on the page itself in the following manner:

Code:
<a href="(URL address blocked: See forum rules)/1.html">keyword 1</a>
<a href="(URL address blocked: See forum rules)/2.html">keyword 2</a>
<a href="(URL address blocked: See forum rules)/my.html">keyword 3</a>
<a href="(URL address blocked: See forum rules)/new.html">keyword 4</a>

etc

There is no database or external files requird..


I hope its easy to understand now..


If anyone can create this script then I would be very greatful..

Thanks
Monicka

Reply With Quote
  #4  
Old October 23rd, 2009, 12:55 PM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 5 Days 1 h 54 m 18 sec
Reputation Power: 4
I'm not trying to be rude, but this is a help forum. Meaning that we are here to help you with the code you have written, not write the code for you. If you want someone to just write the code for you, there is a barter forum where you can hire someone to do the job for you. The code I did above was just a starter to get you pointed in the right direction.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > php5 - Hyperlinks creation


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.

Request Your Free Technology Downloads!
 
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.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
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.

Request Your Free Technology Downloads!
 
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.

Request Your Free Technology Downloads!
 

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




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek