Jump to content

putting a php code into another php code, possible?


cihan

Recommended Posts

Hi, i'm a wordpress user and i have a php code, and in that php code there is an area to put a url in:

$url = "http://blabla.com";

Well, in wordpress you can display post permalinks with this code:

<?php the_permalink(); ?>

What i want to do is putting

<?php the_permalink(); ?>

instead of http://blabla.com above in the php code. Target is: Getting permalinks and putting them there in php code, and let the php code use them to do its job. Is that possible? If yes, how with an example please...Thank you...

i'm trying to put the permalink into this php code:

 

<?php

$url = "http://blabla.com";

$allowedDomains = array
(
    'rapidshare',
    'megaupload',
    'depositfiles',
    'letitbit',
    'hotfile',
    'sherebee',
    'filefactory',
    'zshare',
    'sendspace',
    'uploadbox',
    'uploading',
    '4shared',
    'gigasize',
    'mediafire',
    'netload',
    'linksave',
    'filehoster',
    'rghost',
    'protector'
);

$page = file_get_contents($url);
preg_match_all("/<a.*?href=(\"|\')(.*?)\\1.*?>.*?<\/a>/is", $page, $matches);


echo "<pre>";
//print_r($matches);
echo "<pre>";

echo "Download Links:";
echo "<ul> ";
foreach ($matches[2] as $match)
{
    $validDomain = false;
    foreach ($allowedDomains as $domain)
    {
        if (strpos($match, $domain))
        {
            $validDomain = true;
            break;
      }
    }

    if ($validDomain)
    {
        echo "<li><a href=\"{$match}\">{$match}</a></li>";
    }
}
echo "</ul> ";

?>

 

and get_the_permalink(); is not working, either...

 

 

OK, the Wordpress functions aren't working because you're not declaring them in the PHP code. 

 

Like I said not sure how Wordpress works but somewhere it will declare functions, i.e. with an include or similar.  You need to make sure this is included in your code above so the Wordpress functions will run.

 

Hope this helps.

 

EDIT: Just downloaded Wordpress and these are hopefully the lines you need to include:

 

define( 'ABSPATH', dirname(__FILE__) . '/' );
require_once( ABSPATH . '/wp-includes/classes.php' );
require_once( ABSPATH . '/wp-includes/functions.php' );
require_once( ABSPATH . '/wp-includes/plugin.php' );

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.