Generating a PDF document-PHP



Generating a PDF document
<?php
// These values are in points (1/72nd of an inch)

$fontsize = 72;     // 1 inch high letters

$page_height = 612; // 8.5 inch high page

$page_width = 792;  // 11 inch wide page



// Use a default message if none is supplied

if (strlen(trim($_GET['message']))) {

    $message = trim($_GET['message']);

} else {

    $message = 'Generate a PDF!';

}



// Create a new PDF document in memory

$pdf = pdf_new( );

pdf_open_file($pdf, '');



// Add a 11"x8.5" page to the document

pdf_begin_page($pdf, $page_width, $page_height);



// Select the Helvetica font at 72 points

$font = pdf_findfont($pdf, "Helvetica", "winansi", 0);

pdf_setfont($pdf, $font, $fontsize);



// Display the message centered on the page

pdf_show_boxed($pdf, $message, 0, ($page_height-$fontsize)/2,

               $page_width, $fontsize, 'center');



// End the page and the document

pdf_end_page($pdf);

pdf_close($pdf);



// Get the contents of the document and delete it from memory

$pdf_doc = pdf_get_buffer($pdf);

pdf_delete($pdf);



// Send appropriate headers and the document contents

header('Content-Type: application/pdf');

header('Content-Length: ' . strlen($pdf_doc));

print $pdf_doc;
 
?>
the functions in the PDF extension. 
This extension depends on the PDFLib 
library that is available at
 http://www.pdflibrary.com
The CLibPDF extension also generates
 PDF files, 

PHP and Javascript Variables

Variables

To define a variable in PHP, you’d write:
// PHP
$n = 1;
The equivalent in JavaScript is:
// JavaScript
var n = 1;

There’s no dollar sign, just the name of the variable.
 Like in PHP, you don’t define variable
types because the type is derived from the value.
 You use varfor all types.

If you need a numeric type, you give your variable a
 numeric value. The same applies
to booleans and strings:

var n = 1;  // number
var b = true;  // boolean
var s = "hello"; // string

You have the option of declaring a variable without
 initializing it with a value. In such cases, the variable
 is assigned the special value undefined:
var a;
a; // `a` has the special value `undefined`

Redeclaring an existing variable doesn’t set the variable
 value back to undefined:

var a = 1;
var a;
// `a` is still 1

You can declare and optionally initialize with a
 value several variables with one var statement as
 long as you separate them with a comma and
 end with a semicolon:

var pi = 3.14,
yeps = true,
nopes,
hi = "hello",
wrrrld = "world";

Technically, var is optional. But unless the variable
 was defined higher up in the scope chain , if youskip
 var, you end up with a global variable.

And you’ve learned, prob‐ably the hard way, that
 global namespace pollution is a sin. Additionally,
there are some subtle differences if you declare
 a global variable with and without var.

To cut a long story short, resist this temptation and
always use varto declare your variables.

Multimedia Video Formats

The AVI Format

The AVI Audio Video Interleave format was developed
 by Microsoft.The AVI format is supported by all computers
running Windows, and by all the most popular web browsers.
 It is a very common format on the Internet, but not always
 possible to play on non-Windows computers.
Videos stored in the AVI format have the extension .avi.

The Windows Media Format

The Windows Media format is developed by Microsoft.
Windows Media is a common format on the Internet,
but Windows Media movies cannot be played on
 non-Windows computer without an extra free
 component installed. Some later Windows Media
 movies cannot play at all on non-Windows computers
 because no player is available.Videos stored in the
Windows Media format have the extension .wmv.

The MPEG Format

The MPEG -Moving Pictures Expert Group format is the
 most popular format on the Internet. It is cross-platform,
and  supported by all the most popular web browsers.
Videos stored in the MPEG format have the
extension .mpg or .mpeg.


The RealVideo Format

The RealVideo format was developed for the
 Internet by Real Media.The format allows streaming
of video on-line video, Internet TV with low bandwidths.
 Because of the low bandwidth priority, quality is
 often reduced.Videos stored in the RealVideo format
 have the extension .rm or .ram.

The Shockwave -Flash Format

The Shockwave format was developed by Macromedia.
The Shockwave format requires an extra component to play.
 This component comes preinstalled with the latest versions
of Netscape and Internet Explorer.Videos stored in the
 Shockwave format have the extension .swf.




Google search operators

filetype:

You can restrict your search to Word documents, to Excel documents,
 to PDF files, orto  PowerPoint  files  by  adding  filetype:doc,
  filetype:xls,  filetype:pdf,  or  filetype:ppt,
respectively, to your search query.
Want a great PowerPoint presentation on email marketing that
you can repurpose fora meeting? Simply query Google for
email marketing filetype:ppt. Need a marketing plan
template? Since the template would most likely be a Word
 document, cut through the web page clutter with a search
of marketing plan template filetype:doc. Side note: Don’t
link to your own marketing plans if you don’t want them showing
 up in Google’s index.

In fact, Google allows any extension to be entered in conjunction
 with the  filetype:
operator, including htm, txt, php, asp, jsp, swf, etc.
Google then matches on yourdesired extension after the filename
 in the URL. Note that there is no space after thecolon when using
 this operator. You can use  ext:instead of  filetype:—they do the same
thing.

site:

You can search within a site or a domain by adding the site:
 operator followed by asite’s domain name to your query.
 For example, you could search for  email marketingbut
 restrict your search to only pages within the MarketingProfs
 site with a queryof: email marketing site:www.marketingprofs.com.

You can also add a subdirectory to the end of the domain
 in a site: query. For exampleemail marketing
site:http://www.marketingprofs.com/tlsTo conduct a comprehensive
 search of all of the associated subdomains of a domain,
omit the www and instead specify only the main domain.
 For example, a search forsite:yahoo.com would  encompass
  not  just  www.yahoo.com,  but  also  movies.yahoo.com,
 travel.yahoo.com,  personals.yahoo.com,  etc.,  The
 site:  search  operator works even when just the domain
extension like .com, .org, .gov, or .co.uk is specified.

Thus,  you  can  restrict  your  search  to  .com  sites  with
  site:com,  to  .gov  sites  with site:gov, or to .co.uk with
 site:co.uk.

Combining Boolean logic with the site: operator will allow
 you to search within multiple  sites  simultaneously. 
For  instance,  email  marketing site:marketingprofs.com  |
site:marketingsherpa.com  | site:marketingpower.com searches
 the three sites simultaneously.

The site: operator can be specified by itself without
other search words to get a list of all pages indexed,
 such as site:www.marketingprofs.com. Again, note that there
is no space after the colon when using this operator.
Use this approach to simultaneously search competitor sites for keywords of particular
relevance e.g., related products you want to monitor.

 Then either create a bookmark
to easily monitor the index or create a Google Alert to be
explored later in this book to receive an email any time
 the index changes.

The site:operator works outside of ordinary web search—it also works with Google
Images, Google Product Search, and Google News.

inurl:
Use the inurl:operator to restrict the search results to
 pages that contain a particular word in the web address.
This can be especially useful if you want Google to display
 all the pages it has found within a particular directory
on a particular site, such as inurl:ftp
site:http://www.kellogg.northwestern.eduor all the
 pages with a particular script name, such as
inurl:ToolPage site:http://www.vfinance.com.
Again, there is no space after the colon when using
this operator.

allinurl:

This operator is similar in function to the  inurl:operator,
 but is used for finding multiplewords in the web address.
It eliminates the need to keep repeating  inurl:in front of
every word you want to search for in the URL.
For instance,  allinurl: china exportingis an equivalent
 and more concise form of the
query inurl:china inurl:exportingto find web pages that contain
 the words  chinaandexportinganywhere in the URL,
including the filename, directory names, extension, or
domain. There IS a space after the colon when using the allinurl:operator.
intext:
Searches for a word in the main body text. This is used in a similar fashion to inurl:.
For instance, if you wanted to find only pages that referenced Stephen Hawking and
relativity, you might search for stephen hawking intext:relativity.
allintext:
Searches for multiple words within the body text of indexed pages. This is used in a
similar fashion to allinurl:.

intitle:

Use the intitle: operator (such as intitle:marketing) to look for documents where your
specified word or phrase matches in the page title. This is the hyperlinked text (usually
blue) in the Google search result, which also appears in your browser’s topmost bar.
If you want to find Microsoft Word documents in which the document title (located
within Properties under the File menu in Word) includes the phrase marketing plan,
you would use the query intitle:“marketing plan” filetype:doc. Follow the  intitle: operator with a word or a phrase in quotes, without a space after the colon.

allintitle:

This works like intitle: but searches for multiple words in the title. For instance, use
allintitle: channel conflict online retailto search for documents that contain all four of
those words in the title. Note that there is a space after the colon when using this
operator.

inanchor:

The inanchor: operator will restrict your search to pages where the underlined text of
inbound links matches your search word. For example, if you wanted to search for
merchandising  but  confine  your  search  primarily  to  home  pages,  merchandising
inanchor:homewould do the trick, since most sites link to their own home pages using
the link text of “Home.”
Follow the inanchor: operator with a word or a phrase in quotes, without a space after
the colon.

allinanchor:

This works like inanchor: but searches for multiple words in the link text. For example,
the  query  web  metrics  allinanchor:  download  trial would  invoke  a  search  for  pages
relating to web metrics that have the words downloadand trialin the link text.
Note that there is a space after the colon when using this operator.

daterange:

The daterange: operator restricts the search results to pages added or updated within
the specified date range. Unfortunately, it only accepts Julian dates, which makes it
less user-friendly than it could be. You can find Gregorian-to-Julian date converters
online, e.g. here: http://www.fourmilab.ch/documents/calendar
You’ll usually find it easier just to do your search first without a date range, then use
the custom date range options in the “More search tools” area of the result page.

related:

related: queries show pages that are similar to the specified web page. Follow this operator with a web address, such as  related:http://www.marketingprofs.com, and you
would find web pages that are related to the MarketingProfs home page. This is identical
to the Similar link in the bottom left of the Preview pane of each search result.

info:

An info: query lets you know whether the specified page is known by Google, and it
provides the title and a snippet (if available), a link to the page, a link to a cached version
of the page (see below for an explanation of this), and a link to view pages that link to
the specified page.
Supply a web address after this operator, such as info:http://www.marketingprofs.com.

link:

The link: operator returns a sampling of pages (i.e., a small subset of the total) that link
to the specified web page. Follow this operator with a web address, such as link:http://

cache:

The  cache:  operator  provides  a  snapshot  view  of  a  web  page  as  it  looked  when
Googlebot last  visited  the  page.  Follow  this  operator  with  a  web  address,  such  as
cache:http://www.marketingprofs.comto view the page that Google has cached. Note
that Googlebot must have downloaded the page in order for this to work.

define:

This is a useful operator for quickly obtaining several definitions from various online
glossaries. Curious about the definition of “tipping point”? Simply type define: tipping
pointinto Google.

stocks:

Wondering how your competitor is performing on Wall Street? Enter this operator
followed by a ticker symbol to retrieve financial information, including latest stock
quotes from Google Finance. Note that in most circumstances this operator is optional.
Google figures out if the query is a ticker symbol pretty well.

iPhone 6-water-resistant body

iPhone 6 leak type of weekend - our inbox was buried with all sorts of tips about Apple's upcoming smartphone. After getting compared to the iPhone 5s and the Galaxy S5, the iPhone 6 now sits besides the iPod touch. These alleged comparison shots make the design cues the new smartphone model takes from its music player cousin all the more obvious. Alleged iPhone 6 prototype and iPod touch Additional iPhone 5s / 6 comparison shots made their way out of China along with dimensions - 138 x 67 x 7mm.

 That's considerably larger than the 135.3 x 71.9 x 6.1mm we estimated from the earlier leak. iPhone 6 prototype next to iPhone 5s Keep in mind that this new iPhone is said to have a 4.7" screen, accounting for the larger size. Apple security in China seems to have really broken down as an iPhone 6 dummy was photographed all around a city. Note that this could also be an upcoming knockoff of the iPhone 6 (remember the iploxe?). You can see all photos of the city tour at the Moscoat forum, but these in particular caught our eye. First off, the iPhone 6 gets dunked in water - either because it will be water resistant or because this is a non-working dummy - and then it gets sized up against the iPhone 5s and HTC One M8.

Windows Phone 8.1

Microsoft will begin officially rolling out Windows Phone 8.1 on June 24th. This should coincide with the launch of the Lumia 930, Nokia's upcoming flagship. Just like other iterations of Windows Phone software, 8.1 will feature the typical 3 years of software support and updates.

 Microsoft will make updates available for the Operating System, including security updates, for a minimum of 36 months after the lifecycle start date. These updates will be incremental, with each update built on the update that preceded it. Customers need to install each update in order to remain supported. The distribution of these incremental updates may be controlled by the mobile operator or the phone manufacturer from which you purchased your phone, and installation will require that your phone have any prior updates. Update availability will also vary by country, region, and hardware capabilities. Windows Phone 8.1 brings a host of new features and seems primed to make Microsoft's mobile OS a much more intriguing option for consumers.

Samsung - Tizen handsets - Russia and India

Samsung has been enjoying amazing success with their Galaxy line of handsets rocking Android but they've made it apparent that they plan on launching their own mobile OS: Tizen. Now Tizen isn't exactly well known outside of the more hardcore cell phone fanatic crowd, but the Korean tech giant has already made plans on getting it out there with their newest crop of Galaxy Gear smartwatches. It looks like wearables aren't the only devices that Samsung plans on using Tizen for, however, as there is word that Sammie will try to get Tizen to build traction in markets outside of Europe and the US: namely India and Russia.



 The two regions could see Tizen packing Samsung handsets as early as the next few upcoming weeks. Recently, a Tizen handset was supposed to launch in Japan for the carrier NTT Docomo, however, the deal fell through as NTT deemed that it wasn't the right time for them to do so. Orange in France also got cold feet about releasing Tizen smartphones. Seeing as Tizen isn't exactly getting any love from carriers, it doesn't look like a launch in Europe or the States is going to happen in the near future. However, countries like Russia and India and other emerging markets.

What is an array?

An array is a variablethat stores more than onepiece of related data in a single variable. Think
of an array as a box of chocolateswith slotsinside. The box representsthe arrayitself while
the spacescontaining chocolates representthe valuesstored in the arrays.

Numeric Arrays
Numeric arrays use number as access keys. An access key is a reference to a memory slot in an
array variable. The access key is used whenever we want to read or assign a new value an array
element.
Below is the syntaxfor creating numeric arrays.
$variable_name[n] = value;

<?php
//create an associative array of persons
$persons = array('Mary' => 'Female', 'John' => 'Male', 'Mirriam' => 'Female');
print_r($persons); //print all contents of persons array
echo '<br>'; //create new line
echo 'Mary is a ' . $persons['Mary']; //get mary's gender
?>

Multi-dimensional arrays
These are arraysthat contain other nested arrays. The advantage of multidimensional arrays is
that they allow us to group related datatogether.




Count function
The count functionis used to countthe numberof elementsthat an array contains.
The code
below shows the implementation.

<?php
$lecturers = array('Mr. Jones', 'Mr. Banda', 'Mrs. Smith');
echo count($lecturers); //outputs 3
?>

is_array function
The is_array functionis used to determineif a variableis an arrayor not. Let’s now look at
an example that implements the is_array functions.

<?php
$lecturers = array('Mr. Jones', 'Mr. Banda', 'Mrs. Smith');
echo is_array($lecturers);
?>

The above code outputs
1

Sort – 
this function is used to sort arrays by the values. If the values are alphanumeric, it sorts
them in alphabetical order. If the values are numeric, it sorts them in ascending order. It removes
the existing access keys and add new numeric keys. The output of this function is a numeric
array.

<?php
$persons = array('Mary' => 'Female', 'John' => 'Male', 'Mirriam' => 'Female');
sort($persons);
print_r($persons);
?>

Arrays are special variableswith the capacityto store multi values.

Arrays are flexibilityand can be easily stretchedto accommodate more values.
Numeric arraysuse numbers for the array keys
Associative arraysuse descriptive namesfor array keys
The is_arrayfunction is used to determinewhether a variableis a valid array or not.

Find Links to Any Web Site

When you browse to a web site you've never seen before, you don't have very much advance knowledge about the site. You might know that you've followed a link from a particular site that you read frequently, or you might have found the site in some search results for a certain search term. Of course, the site itself can tell you quite a bit, but that still doesn't give you any clues about where the site fits into the larger Web. With some searching at Yahoo!, you can get extra info about a site by using the special link: syntax.
If you want to find what sites are linking to any other particular site, you can browse to http://search.yahoo.com and  enter this query: link:insert URL.

 Instead of standard search results, Yahoo! will display a list of the sites that link to the URL you've specified in the query. For example, if you'd like to find out where the O'Reilly Hacks site fits into the Web, you could search for link:http://hacks.oreilly.com.
In the results, you immediately get a sense of how many pages link to the site and what kinds of sites are linking there. If you're browsing the Web, leaving a site to do a quick Yahoo! link: search can be annoying if you'd just like to get this sense about the current site you're visiting. To find the sites, you need to copy the current URL from your browser address bar, open a new window or tab, browse to Yahoo!, and then assemble the proper query. It's a quick process, but you can speed it up considerably with a bit of classic ASP and a JavaScript bookmarklet.

This hack uses JavaScript to get the URL of the current page you're viewing in your browser. From there, it passes the URL to a server-side script that assembles the proper Yahoo! query and fetches the top 10 results with Yahoo! Search Web Services. A new pop-up window will give a quick look at which sites are linking to the current page, without leaving your place.

Spider the Yahoo Catalog

Writing a spider to spider an existing spider's site may seem convoluted, but it can prove useful when you're looking for location-based services. This hack walks through creating a framework for full-site spidering, including additional filters to lessen your load.
In this hack, you'll learn how to write a spider that crawls the Yahoo! group of portals. The choice of Yahoo! was obvious; because it is one of the largest Internet portals in existence, it can serve as an ideal example of how one goes about writing a portal spider.
But before we get to the gory details of code, let's define what exactly a portal spider is. While many may argue with such a classification, I maintain that a portal spider is a script that automatically downloads all documents from a preselected range of URLs found on the portal's site or a group of sites, as is the case with Yahoo!. A portal spider's main job is to walk from one document to another, extract URLs from downloaded HTML, process said URLs, and go to another document, repeating the cycle until it runs out of URLs to visit. Once you create code that describes such basic behavior, you can add additional functionality, turning your general portal spider into a specialized one.
Although writing a script that walks from one Yahoo! page to another sounds simple, it isn't, because there is no general pattern followed by all Yahoo! sites or sections within those sites. Furthermore, Yahoo! is not a single site with a nice link layout that can be described using a simple algorithm and a classic data structure. Instead, it is a collection of well over 30 thematic sites, each with its own document layout, naming conventions, and peculiarities in page design and URL patterns. For example, if you check links to the same directory section on different Yahoo! sites, you will find that some of them begin with http://www.yahoo.com/r, some begin with http://uk.yahoo.com/r/hp/dr, and others begin with http://kr.yahoo.com.

If you try to look for patterns, you will soon find yourself writing long if/ elsif/else sections that are hard to maintain and need to be rewritten every time Yahoo! makes a small change to one of its sites. If you follow that route, you will soon discover that you need to write hundreds of lines of code to describe every kind of behavior you want to build into your spider.

This is particularly frustrating to programmers who expect to write code that uses elegant algorithms and nicely structured data. The hard truth about portals is that you cannot expect elegance and ease of spidering. Instead, prepare yourself for a lot of detective work and writing (and throwing away) chunks of code in a hit-and-miss fashion. Portal spiders are written in an organic, unstructured way, and the only rule you should follow is to keep things simple and add specific functionality only once you have the general behavior working.

Okaywith taxonomy and general advice behind us, we can get to the gist of the matter. The spider in this hack is a relatively simple tool for crawling Yahoo! sites. It makes no assumptions about the layout of the sites; in fact, it makes almost no assumptions whatsoever and can easily be adapted to other portals or even groups of portals. You can use it as a framework for writing specialized spiders.

Save the following code to a file called yspider.pl: