Jump to content

Recommended Posts

Hi

 

I need some help to get this done using php:

 

 

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

 

<a href="http://domaina.com/1.html" target="_blank">http://domaina.com/1.html</a>

<a href="http://domainb.com/1.html" target="_blank">http://domainb.com/1.html</a>

<a href="http://domainc.com/21.html" target="_blank">http://domainc.com/21.html</a>

<a href="http://domaind.com/new.php" target="_blank">http://domaind.com/new.php</a>

 

etc etc

 

Now I want to convert them into format like:

 

<a href="http://domaina.com/1.html" target="_blank">keyword 1</a>

<a href="http://domainb.com/1.html" target="_blank">keyword 2</a>

<a href="http://domainc.com/21.html" target="_blank">keyword 3</a>

<a href="http://domaind.com/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

Link to comment
https://forums.phpfreaks.com/topic/178636-php-hyperlinks-generator/
Share on other sites

Hello!

 

I can help you with this code, but first I need to know a few things:

 

1) You say "I have few hyperlinks say 500 in format like:"

-Where are these? Are they being generated? In a table ... a file?

 

2) You have a file of keywords ... how are they delimited. Comma, newline, space

 

Ben

 

 

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

 

http://domaina.com/1.html

http://domainb.com/2.html

http://domaind.com/my.html

http://domaina.com/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:

 

<a href="http://domaina.com/1.html">keyword 1</a>

<a href="http://domainb.com/2.html">keyword 2</a>

<a href="http://domaind.com/my.html">keyword 3</a>

<a href="http://domaina.com/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

 

 

 

 

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <table>
        <tr>
            <td valign="top"><strong>URLs</strong><br/><textarea cols="50" rows="4" name="urls" id="urls"></textarea></td>
            <td valign="top"><strong>Keywords</strong><br/><textarea cols="50" rows="4" name="keywords" id="keywords"></textarea></td>
        </tr>
        <tr>
            <td colspan="2"><input type="submit" text="Submit"></td>
        </tr>
    </table>
</form>

<?php

$out = "";

if($_POST['urls'] != "" && $_POST['keywords'] != "")
{
    $keywords = explode("\n", $_POST['keywords']);
    
    $urls = explode("\n", $_POST['urls']);
    
    $out = "";
    
    for($i = 0; $i < count($urls); $i++)
    {
        $out .= "<a href='". $urls[$i] ."'>". ($keywords[$i] == "" ? $urls[$i] : $keywords[$i]) ."</a><br/>\n"; 
    }
}

echo $out;
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.