PHP’s nowdoc strings

PHP has heredoc syntax like other programming languages to interpolate variables into large string blocks (which I’ve covered in an earlier post). In PHP 5.3.0 a new string delimiter was introduced called "nowdoc" which works in the same was as heredoc but acts like a single quoted string, so no variable interpolation or parsing is done.

Categories PHP

Resolving relative URLs to absolute in PHP

When scraping content using the PHP Simple HTML DOM Parser it is useful to resolve relative URLs in a page to absolute URLs for downloading additional web pages or images. I do this using the url_to_absolute library byNadeau Software Consulting and show how to do this here, along with a minor fix which needs to be done to their code.

Categories PHP

Copying an object in PHP with clone

Objects in PHP are assigned by reference, so copying an object with the = operator will result in a second variable referencing the same object and not an actual copy. Enter PHP’s clone function which creates a shallow copy of the object.

Categories PHP