Code Examples About Php

Here you can find a list of code examples. Most are just documented functions. This is becoming my sort of personal code documentation repository. However, some examples have file attachments that you can download. All code exposed here is free and can be used without permission. No warranty is implied, but if you have questions about something, feel free to ask by posting a comment.

  • Separate Email Addresses

    This is a quick script to diff two files which contain email addresses putting the emails in file A which do not exist in file B into file C.
  • apply_input_filter_rules

    Purpose: To auto set and hide drupal input format settings. The input format settings don't always makes sense to the uninitiated and so it's often nice to just set them and forget them for certain users. This function helps accomplish that, although it'll need to be customized for every unique situation.

    Description: Recursively finds specified input format fields in a drupal forms API array and auto sets them depending on configured rules. The rules are configured inside the function. It would be better to pull these rules out to make the function generic, but this is good enough for me for now. If someone else uses this function I'll probably make it more generic.

  • override_submit_buttons

    Purpose: Overrides drupal forms API submit buttons. Creates nice, rounded corner submit buttons using a hacky table tag. Sprinkle in imagery and css as necessary. It relies on a theme function called 'blank_image' that just renders a 1px X 1px transparent gif used to fill space so that the thing will work right in IE6.

    Description: This is a recursive funtion which searches through all the child elements of the current element. When it finds an element determined to be a button, it appends a link button at the end of the button. The link button will call the button's click() function on click. Therefore, it essentially replaces the button. We send down both the input form element and the link button so that we can degrade gracefully if the user doesn't have javascript.

  • closetags

    Purpose: To find all unclosed tags in a snippet of HTML and close them.

    Description: Takes in a string of HTML (or anything string), finds all unclosed tags, then returns a string of HTML with the tags closed.

  • truncate

    Purpose: To truncate a snippet of HTML code to a specific length.

    Description: Takes in a string of HTML (or anything string), then truncates it to a specified length, trimming only on a word boundary. It will also add an elipsis at the end and a "more" link.