PHP Simple HTML DOM Parser function to parse(get anchore tag) from html source - php-parser

I need to find a way to request the href & value of all <a elements from HTML file.
For example:
Domain Link
Output:
href: 'http://domain.com'
value: 'Domain Link'

Try this code.
$html=file_get_html($url);
foreach ($html->find('a') as $links){
//Get link text
echo $links->innertext;
//Get href value
echo $links->href;
}

Related

WWW::Mechanize::Firefox put content into input by id

I am using WWW::Mechanize::Firefox. How to put content into input by id and after that to press link witch, using JS, submit page?
<input id="my_input" type="text" class="some_class"/>
<a id="send_with_me" href="#">Press me</a>
How to do it?
Thanks
Answer to request of Borodin:
my $mech = WWW::Mechanize::Firefox->new(
activate => 1
);
my $content = $mech->get("http://some_url.com");
$mech->field(".my_select_element_by_class", 1); #select element from select by class
I want to put value into input by id. Something like this:
$mech->field("#my_input", 100);
$mech->some_method_witch_press_href("#send_with_me");
You need this to click the link (by CSS selector):
$mech->field("#my_input", 100);
$mech->click({ selector => '#some_id' });

Open FPDF in new tab

I have a pdf generated (fpdf) from a post form. I would like the pdf to open in a new tab and/or window prompting the user to save the pdf. I'm guessing I need to save the output to a string
$data=$pdf->Output("OfficeForm.pdf", "S");
but what exactly can I do with this string to get it to open in a new window. I've attempted something like this but it's not working. Am I on the right track or is window.open not what I need?
echo "<script type=\"text/javascript\">
window.open('$data', '_blank')
</script>";
If you use a form you can do it by specifying target='_blank' in the -tag (next to where you should have submit='something')
Example:
This will open a new Tab (showing whatever "makepdf.php" produces) on submit.
Hope it answers the question correctly
I simply added target="_blank" to my form opening tag and used $_SESSION[]; to pass my form to the FPDF code:
<?php session_start(); ?>
<form id ="buildPDFform" name="buildPDFform" target="_blank" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
...some code for my form
<input type="submit" name="buildPDf" id="buildPDf" class="buildPDFbutton" value="Build the PDF">
</form>
Then when the form is submitted I gather my form items, put them in an array, create a session the array goes into and use a header("Location: testcode.php") to redirect to where my FPDF code is.
if (isset($_POST['buildPDf'])) {
$pdfArray = array();
foreach ($_POST as $key => $value) {
...gather your form items into your array
}
$_SESSION['pdfArray'] = $pdfArray;
header("Location: testcode.php");
}
And don't forget in your FPDF code file (testcode.php in my case) to grab your session that has the array.
<?php
session_start();
$pdfArray = $_SESSION['pdfArray'];
... your FPDF code
$pdf->Output('I');
?>
source: https://www.thesitewizard.com/html-tutorial/open-links-in-new-window-or-tab.shtml
use target="_blank" in your a tag to open it to new tab
Try $pdf->Output("OfficeForm.pdf", "I");

How to send a POST image url variable through a form in Laravel 4

I am trying to upload an image url through a form in Laravel 4.
Without a framework, I would use something like this:
<div id="myResults" value="<php echo h($_POST['img'])"></div>
where the image url is sent to the id "myResults" by a javascript file.
In the javascript:
document.getElementById("myResults").innerHTML = "<img src='" + FPFile.url + "' width='200px' height='200px'>";
I would use the h($_POST['img'])" value to get the url and then store it in the database upon the submit click of the form.
My question is how can I do this same function in Laravel 4? Using the form:
{{ Form::open(array('route' => 'artists.store')) }}
{{Form::submit('Submit', null, array(
'class' => 'button',
));}}
Thank you for your help.
{{ Form::file('myImage') }}
Seriously, it's that easy! See: http://laravel.com/docs/html
Then, to retrieve the file: $file = Input::file('myImage');
See: http://laravel.com/docs/requests#files
I'm not really understanding your question.
But equivalent of
<div id="myResults" value="<php echo h($_POST['img'])"></div>
in Blade is...
<div id="myResults" value="{{{ Input::get("img") }}}"></div>
Is that what you were asking?

How to make a page-specific title in Dancer templates?

I have a standard Perl Dancer app, using Template::Toolkit as rendering engine, with two routes:
get '/' => sub {
template 'index';
};
get '/foo' => sub {
template 'foo';
};
My views/templates/main.tt contains the line:
<title><%= title %></title>
I want the value of title var be "My Site" on page '/', and "Foo - My Site" on page '/foo'.
I know I can put these values in the controller file, like this:
template 'index', { title => 'My Site' };
but I want to specify them in the corresponding template files, views/index.tt and views/foo.tt.
How can I do that?
Thanks.
This documentation clearly explains how to configure your application to make available in your layout the variables defined in your templates.
For the title tag, you can save yourself the effort to define the title in each template using the variable template.name. Maybe something like that:
<title>
<% template.name.match('(\w+).tt').0.ucfirst %> - <% settings.sitename %>
</title>

How to use Facebook FBJS Feed Forms

I'm trying to call a Feed Form in my Facebook application and I'm not sure how to do so. I'm not familiar with the FBJS and its API. Specifically I need the following dialogue to show up: http://wiki.developers.facebook.com/index.php/Feed_Forms
Here's what I got for now:
<script type="text/javascript">
var attachment = <?php echo json_encode($attachment); ?>;
return attachment;
Facebook.streamPublish(<?php echo $message; ?>, attachment, null, <?php echo $user; ?>);
</script>
Is there anything else I need to do in order to properly call a Feed form? A code example would help me a lot if anyone is willing to write one up.
Here's an example I use from a Facebook Connect site that I operate:
var message = 'This is my message!';
var attachment = {
'name':'Page name',
'href':'http://mysite.com',
'caption':'Some kind of caption';
};
attachment.media = [{'type':'image','src':'http://mysite.com/images/lolcat.jpg','href':'http://mysite.com'}];
var action_links = [{'text':'Action Link!','href':'http://mysite.com'}];
FB.Connect.streamPublish(message, attachment, action_links);
The FB.Connect methods are almost identical to the normal JS methods, so something similar should be working for you.
I would point out that you have <?php echo $message; ?> as the first parameter to your Facebook.streamPublish() call. Assuming $message is a text string, then you need to wrap that output in quotes in order for it to be valid Javascript. As well, the return attachment; line doesn't make much sense to me. Why is there a return statement there? I would change your code to this:
<script type="text/javascript">
var attachment = <?php echo json_encode($attachment); ?>;
Facebook.streamPublish('<?php echo addslashes($message); ?>', attachment, null, <?php echo $user; ?>);
</script>
For FBML canvas pages, all you need to do is execute the command as follows:
<script type="text/javascript">
var attachment = <?php echo json_encode($attachment); ?>;
Facebook.streamPublish('', attachment, null);
</script>
That should easily bring up the Feed Form.