Skip to content

Instantly share code, notes, and snippets.

@tonylegrone
Created February 26, 2013 19:23
Show Gist options
  • Save tonylegrone/5041288 to your computer and use it in GitHub Desktop.
Save tonylegrone/5041288 to your computer and use it in GitHub Desktop.
<?php
/**
* Injects a string into an existing string in the designated position.
* HTML should not be effected, but who knows.
*
* @param string $inject
* The new string to be injected.
* @param string $string
* The original string to be alter.
* @param int $pos
* The word posion to inject the new string at. Zero is ahead of the
* original string.
* @return string
* Returns the new injected string.
*/
function str_inject($inject, $string, $pos) {
$string = explode (' ', $string);
array_splice($string, $pos, 0, $inject);
return implode(' ', $string);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment