Jump to content

need some help of onclick button in php


blacktiger786

Recommended Posts

i have this code which fetch meta tags and title

function file_get_contents_curl($url)
{
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

    $data = curl_exec($ch);
    curl_close($ch);

    return $data;
}

$html = file_get_contents_curl("http://example.com/");

//parsing begins here:
$doc = new DOMDocument();
@$doc->loadHTML($html);
$nodes = $doc->getElementsByTagName('title');

//get and display what you need:
$title = $nodes->item(0)->nodeValue;

$metas = $doc->getElementsByTagName('meta');

for ($i = 0; $i < $metas->length; $i++)
{
    $meta = $metas->item($i);
    if($meta->getAttribute('name') == 'description')
        $description = $meta->getAttribute('content');
    if($meta->getAttribute('name') == 'keywords')
        $keywords = $meta->getAttribute('content');
}

if(!title == ' ')
{
echo ' found a title';
}

in this code you see in last i have if condition (!title==' ') its execute it when i open file

i want its only run when i click the html button like

<input type="button" name="Release" onclick="" value="Click ">

please tell me what i do help me

Link to comment
Share on other sites

The above is PHP code. But, that condition is invalid - you are missing the dollar sign at the beginning of the variable name: $title

 

Plus, to do something "onclick" requires that you either submit the page and process the POST/GET data or you need to implement JavaScript to perform an AJAX request. I assume you want the latter. But, there's too much to try and tell you how to do this in a forum post. I would suggest you look up on how to implement JQuery's AJAX functionality.

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.