You wouldn't include JS files within the PHP, they would be output as script tags within the HTML you produce which you may be producing as output from the PHP script.
As far as I know, there is no built in CodeIginiter function to include this output like there is for CSS using the link_tag()
function provided by CI. I've added a function called script_tag()
to the system/helpers/html_helper.php
file from CI. The function is:
if ( ! function_exists('script_tag')) {
function script_tag($src = '', $language = 'javascript', $type = 'text/javascript', $index_page = FALSE)
{
$CI =& get_instance();
$script = '<scr'.'ipt';
if (is_array($src)) {
foreach ($src as $k=>$v) {
if ($k == 'src' AND strpos($v, '://') === FALSE) {
if ($index_page === TRUE) {
$script .= ' src="'.$CI->config->site_url($v).'"';
}
else {
$script .= ' src="'.$CI->config->slash_item('base_url').$v.'"';
}
}
else {
$script .= "$k=\"$v\"";
}
}
$script .= "></scr"."ipt>\n";
}
else {
if ( strpos($src, '://') !== FALSE) {
$script .= ' src="'.$src.'" ';
}
elseif ($index_page === TRUE) {
$script .= ' src="'.$CI->config->site_url($src).'" ';
}
else {
$script .= ' src="'.$CI->config->slash_item('base_url').$src.'" ';
}
$script .= 'language="'.$language.'" type="'.$type.'"';
$script .= ' /></scr'.'ipt>'."\n";
}
return $script;
}
}
Then in your PHP code you can do:
echo script_tag('content/js/jquery-1.4.2.js');