• The eternal confessions of a beautiful mind...
  • DamianM.Co.UK
  • Home
  • About
  • Archives
  • Contact
  • Sitemap
  • My Flickr

    IMG_4129IMG_4123IMG_4112IMG_4111IMG_4099IMG_4098IMG_4097IMG_4095IMG_4094IMG_4093IMG_4092IMG_4091IMG_4090IMG_4089IMG_4088IMG_4087IMG_4086IMG_4085IMG_4084IMG_4083
  • Recent Posts

    • Pump My Ride
    • Can you spell …
    • End of an E.ON
    • Drumming Ape Gets New Gig
    • Star wars explained by a 3 year old
    • Gene Hunt “Bunny Killer”
    • Coffee Table
    • Need Glasses?
    • Third Nipple
    • Helpdesk of the darkside
    • Optical Illusion
    • Dirty mind test
    • Silly funny video
    • Dalek Cam
    • Autobiographies
  • My Tools

    • RSS_Sticky
    • WordPress.org
    • WP_BlogNetworking
    • WP_BoilerPlate
    • WP_Censor
    • WP_DeliciousPost
    • WP_EasyReply
    • WP_HeadNFoot
    • WP_LinkIt
    • WP_LinkSync
    • WP_OneInstall
    • WP_PostDate
    • WP_PostNotes
    • WP_Spoiler
    • WP_StumbleDigest
    • WP_Submission
  • My Web

    • ASPAlliance
    • ClaimID
    • Digg
    • DSLRBlog
    • DVDProfiler
    • Flickr
    • Honeyed SPAM
    • My Blog
    • My company
    • MYSpace
    • MySQL
    • WordPress.org
    • YouTube

    PHP Tip: Output Control Functions

    January 23rd, 2008

    Over the last year or so I’ve been getting used to programming in PHP, and I’ve long been at a stage when I can say my PHP skills are as good if not better than my skills in ASP.NET or ASP, an that I can accomplish more or less anything I need to in PHP.

    However I would not say that I know PHP inside out, there are many function around the margins that you would not use day to day that might be very useful. There are times when I need to do things that send me trawling though the PHP site to find anything that will make the task possible or at least a little easier. But as with anything if you don’t use it regular you will soon forget what you can do and you have to research it again the next time.

    Here I plan to document everything that I discover, no matter how little as a quick reference for me, and hopeful some sort of help to others.

    I do a lot of work with WordPress which involves using its API. This can be a little frustrating sometimes, nothing more so that when you find the feature you need to it outputs directly to the screen, and there is no alternate function that allows you to execute the function into a variable. A couple of functions like this are next_posts_link and previous_posts_link that are used to display next and previous buttons on the site. For me they work fine individually and only display is needed, but I’d like to know if neither are shown so i can do something else. After trawling the API for an alternative and finding nothing, and not wanting to write a non API solution that may not be compatible with future release, I fell upon a kludgy but very workable solution.

    PHP has a set of Output Control Functions that allow interception of any screen output into a buffer. There are many function in this section that maybe useful, but the ones i found useful are

    • ob_start: which start the interception of all output.
    • ob_get_contents: that lets you read all the buffered output up to this point into a variable.
    • ob_end_clean: that finishes the buffering of the out put.

    Here is an example of how I used these commands to solve the WordPress problem

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    
     ob_start();
     
     next_posts_link('« Previous');
     
     $previous = ob_get_contents();
     
     ob_end_clean();
     
     ob_start();
     
     previous_posts_link('Next »');
     
     $next = ob_get_contents();
     
     ob_end_clean();
     
    ?>

    Posted in Coding | No Comments »

    Cross Platform Stylesheets

    July 9th, 2007

    Having just finished my first theme for My Blog, I am a little more aware of some of the pitfalls of writing a stylesheet that looks well on a number of platforms. Having first designing the CSS on Firefox and checking that it validated using the W3C own checker i was a bit annoyed that it didn’t look as expected when i went to check it in IE. Okay there are a few little things that can be overlooked like the listitem bullets looked a little different but there where differences in i the layout. Having spend hours trying to come to terms with the problem i found that even though IE and Firefox both connform to the same standard ( which i take on faith ) it would appear that they both start with different defaults.

    So to ensure that you CSS looks they way you are designing it across all platforms bear that in mind.  Never rely on the fact that they margins and padding on the DIV default the way you want them.

    Posted in Blurb, Coding, advice | 1 Comment »

    WP_RSS_Sticky

    July 9th, 2007

    I’ve just release a WordPress plugin over on My company site, WP_RSS_Sticky. A plugin to allow you to insert copyright or other messages in the articles in your RSS Feed.

    Posted in Coding, Wordpress | 1 Comment »