Beamer/LaTeX Tutorial
LaTeX is commonly used to prepare documents. It is commonly used for the scientific documentation because it is very useful to create documents with lots of mathematical symbols and notations. For some time, Beamer is used by the scientific community for preparing slides for a presentation. Beamer has features to describe slides and the transition. So creating slides with Beamer is very quick.
If you want to work with LaTeX/Beamer in Linux, you have the command line utilities like pdflatex to create pdf documents from .tex documents. You can also work with application softwares like kile.
- Installation
- Creating Slides
PHP: Extract Outgoing URLs from a Web Page
In PHP, you can download a web page using file_get_contents or curl. Once you have downloaded a web page, you can process it.
We know that the tag structure of hyperlink is as follows
<a href="http://www.joysofprogramming.com">Joys of Programming</a>
Keeping this in mind, we write the following program
<?php
function extractElementsFromWebPage($webPage, $tagName) {
//Creating a DOMDocument Object.
$dom = new DOMDocument;
//Parsing the HTML from the web page
if ($dom->loadHTML($webPage)) {
// Extracting the specified elements from the web page
@$elements = $dom->getElementsByTagName($tagName);
return $elements;
}
return FALSE;
}
function downloadURL($URL) {
$webPage = file_get_contents ($URL);
return $webPage;
}
$webPage = downloadURL("http://www.mozilla.org/");
if ($webPage ) {
$URLs = extractElementsFromWebPage($webPage, 'a');
if ($URLs) {
foreach ($URLs as $URL){
// Extracting the URLs
echo $URL->getAttribute('href'), "\n";
}
}
else {
echo "Error in parsing the webPage\n";
}
}
else {
echo "Error in downloading the webPage\n";
}
?>
There are certain things that need to be understood:
Firstly we are using file_get_contents to download a web page. Then we use the DOMDocument class in PHP to parse the HTML page. Check the two functions
- downloadURL
- extractElementsFromWebPage
downloadURL uses file_get_contents to download the web page and extractElementsFromWebPage uses the DOMDocument class. The function loadHTML is used to parse the HTML page and getElementsByTagName to extract the specified elements. In our case, we want to extract the HTML tag element a.
On executing the program
$ php extractURLs.php #main / /about/ /community/ /projects/ /contribute/ /about/mission.html http://www.mozilla.com/firefox/ http://www.mozilla.com/mobile/download/ ...
PHP: Extract Image URLs from a Web Page
In PHP, you can download a web page using file_get_contents or curl. Once you have downloaded a web page, you can process it. We want to extract the image URLs from a web page.
We know that the tag structure of an image url is as follows
<img src="image.gif" alt="Image Description" />
Keeping this in mind, we write the following program
<?php
function extractElementsFromWebPage($webPage, $tagName) {
//Creating a DOMDocument Object.
$dom = new DOMDocument;
//Parsing the HTML from the web page
if ($dom->loadHTML($webPage)) {
// Extracting the specified elements from the web page
@$elements = $dom->getElementsByTagName($tagName);
return $elements;
}
return FALSE;
}
function downloadURL($URL) {
$webPage = file_get_contents ($URL);
return $webPage;
}
$webPage = downloadURL("http://www.mozilla.org/");
if ($webPage ) {
$imageURLURLs = extractElementsFromWebPage($webPage, 'img');
if ($imageURLURLs) {
foreach ($imageURLURLs as $imageURL){
// Extracting the URLs
echo $imageURL->getAttribute('src'), "\n";
}
}
else {
echo "Error in parsing the webPage\n";
}
}
else {
echo "Error in downloading the webPage\n";
}
?>
There are certain things that need to be understood:
Firstly we are using file_get_contents to download a web page. Then we use the DOMDocument class in PHP to parse the HTML page. Check the two functions
- downloadURL
- extractElementsFromWebPage
downloadURL uses file_get_contents to download the web page and extractElementsFromWebPage uses the DOMDocument class. The function loadHTML is used to parse the HTML page and getElementsByTagName to extract the specified elements. In our case, we want to extract the HTML tag element img.
On executing the program
$ php extractImageURLs.php /images/promos/join_promo_a.png /images/template/screen/logo_footer.png https://statse.webtrendslive.com/dcsis0ifv10000gg3ag82u4rf_7b1e/njs.gif?dcsuri=/nojavascript&WT.js=No&WT.tv=8.6.2
PHP: Extract HTML Tags/Element from a Web Page
In PHP, you can download a web page using file_get_contents or curl. Once you have downloaded a web page, you can process it. Take for example, we want to extract the image URLs from a web page.
We know that the tag structure of an image url is as follows
<img src="image.gif" alt="Image Description" />
Keeping this in mind, we write the following program
<?php
function extractElementsFromWebPage($webPage, $tagName) {
//Creating a DOMDocument Object.
$dom = new DOMDocument;
//Parsing the HTML from the web page
if ($dom->loadHTML($webPage)) {
// Extracting the specified elements from the web page
@$elements = $dom->getElementsByTagName($tagName);
return $elements;
}
return FALSE;
}
function downloadURL($URL) {
$webPage = file_get_contents ($URL);
return $webPage;
}
$webPage = downloadURL("http://www.mozilla.org/");
if ($webPage ) {
$imageURLURLs = extractElementsFromWebPage($webPage, 'img');
if ($imageURLURLs) {
foreach ($imageURLURLs as $imageURL){
// Extracting the URLs
echo $imageURL->getAttribute('src'), "\n";
}
}
else {
echo "Error in parsing the webPage\n";
}
}
else {
echo "Error in downloading the webPage\n";
}
?>
There are certain things that need to be understood:
Firstly we are using file_get_contents to download a web page. Then we use the DOMDocument class in PHP to parse the HTML page. Check the two functions
- downloadURL
- extractElementsFromWebPage
downloadURL uses file_get_contents to download the web page and extractElementsFromWebPage uses the DOMDocument class. The function loadHTML is used to parse the HTML page and getElementsByTagName to extract the specified elements. In our case, we want to extract the HTML tag element img.
On executing the program
$ php extractElements.php /images/promos/join_promo_a.png /images/template/screen/logo_footer.png https://statse.webtrendslive.com/dcsis0ifv10000gg3ag82u4rf_7b1e/njs.gif?dcsuri=/nojavascript&WT.js=No&WT.tv=8.6.2
PHP: Download Web Page using file_get_contents
You can use curl to download a webpage in PHP. It is also possible to download a web page using file_get_contents().
<?php
function downloadURL($URL) {
$webpage = file_get_contents ($URL);
return $webpage;
}
$webpage = downloadURL("http://www.mozilla.org/");
if ($webpage){
echo $webpage;
}
else {
echo "Error in downloading the webpage\n";
}
?>
$ php download.php <html> .... </body> </html>
In the above example, we try to download the web page of Mozilla. Let’s try to download a non existing web page
<?php
function downloadURL($URL) {
$webpage = file_get_contents ($URL);
return $webpage;
}
$webpage = downloadURL("http://www.mozilla.org/1");
if ($webpage){
echo $webpage;
}
else {
echo "Error in downloading the webpage\n";
}
?>
We find the following error
$ php download.php Warning: file_get_contents(http://www.mozilla.org/1): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/prof/samuel/Documents/Dropbox/Personal/Programs/downloadWebpage.php on line 4 Error in downloading the webpage
Google Chrome: Unable to Open in Mac
There can be many reasons why you can’t open Google Chrome in Mac. To diagnose this issue, try typing the following in the Terminal and run Chrome from the terminal
$ /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome [......:ERROR:process_singleton_mac.cc(102)] Unable to obtain profile lock.
If you get the following error, you must remove the following file
$ rm ~/Library/Application\ Support/Google/Chrome/SingletonLock
And now try opening Google Chrome.