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

Link to comment
Share on other sites

Do you mean:

 

$url = "the_permalink();";

 

or

 

$url = the_permalink();

 

I tried both of them but not working...

 

Warning: file_get_contents(the_permalink();) [function.file-get-contents]: failed to open stream: No such file or directory

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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' );

 

Link to comment
Share on other sites

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.