balkan7 Posted November 17, 2009 Share Posted November 17, 2009 Hi, i need help for add custom code like javascript or css to head, i have function for it but i'm confused , here is code: header.php <?php <html> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title><?php echo EMS_CAD; ?></title> <link rel="stylesheet" href="style.css" type="text/css" media="screen" /> <?php if (function_exists("add_to_head")) { echo add_to_head(); } ?> </head>?> includes.php <?php $page_head_tags = ""; function add_to_head($tag=""){ global $page_head_tags; if(!stristr($page_head_tags, $tag)){ $page_head_tags .= $tag."\n"; } } ?> index.php <?php add_to_head("<link rel='stylesheet' href='blue.css" type='text/css' media='screen' />");?> Quote Link to comment https://forums.phpfreaks.com/topic/181894-function-add-code-to-head/ Share on other sites More sharing options...
premiso Posted November 17, 2009 Share Posted November 17, 2009 header.php <html> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title><?php echo EMS_CAD; ?></title> <link rel="stylesheet" href="style.css" type="text/css" media="screen" /> <?php if (function_exists("add_to_head")) { echo add_to_head(); } ?> </head> Try that. You only need to open PHP tags when you plan on executing PHP code. Also: index.php <?php add_to_head("<link rel='stylesheet' href='blue.css' type='text/css' media='screen' />");?> You had a syntax error with the double quote after blue.css. Quote Link to comment https://forums.phpfreaks.com/topic/181894-function-add-code-to-head/#findComment-959330 Share on other sites More sharing options...
balkan7 Posted November 17, 2009 Author Share Posted November 17, 2009 i get this error message: Warning: stristr() [function.stristr]: Empty delimiter in C:\xampp\htdocs\testsite\header_includes.php on line 8 Quote Link to comment https://forums.phpfreaks.com/topic/181894-function-add-code-to-head/#findComment-959495 Share on other sites More sharing options...
premiso Posted November 17, 2009 Share Posted November 17, 2009 Well look up the function in the manual and do some debugging to figure out why the delimiter is empty. stristr Quote Link to comment https://forums.phpfreaks.com/topic/181894-function-add-code-to-head/#findComment-959499 Share on other sites More sharing options...
balkan7 Posted November 17, 2009 Author Share Posted November 17, 2009 Maybe my mistake, i review my code but here no errors, why show me empty delimiter header_includes.php <?php $page_head_tags = ""; function add_to_head($tag=""){ global $page_head_tags; if(!stristr($page_head_tags, $tag)){ $page_head_tags .= $tag."\n"; } }?> header.php <?php include("header_includes.php"); ?> <html> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title><?php echo EMS_CAD; ?></title> <meta name="description" content="EMS-CAD, Arhitektura"> <meta name="keywords" content="EMS-CAD, Arhitektura"> <link rel="stylesheet" href="stil.css" type="text/css" media="screen" /> <?php if (function_exists("add_to_head")) { echo add_to_head(); } ?> </head> <body> <table class="table" cellspacing="0" cellpadding="0" align="center"> <tr> <td valign="top" nowrap> <table class="table" cellspacing="0" cellpadding="0"> <tr> <td> <img border="0" src="sliki/header1.jpg" width="400" height="200"></td> <td class="header"><div class="top"> <a href="index.php" title="<?php echo HOME;?>" class="prozirnost"><img src="sliki/naslovna.gif" border="0" alt="<?php echo HOME;?>"></a> <img src="sliki/tocki.gif"> <a href="kontakt.php" title="<?php echo MSG;?>" class="prozirnost"><img src="sliki/mail.gif" border="0" alt="<?php echo MSG;?>"></a> <img src="sliki/tocki.gif"> <a href="#" title="<?php echo MAP;?>" class="prozirnost"><img src="sliki/mapa.gif" border="0" alt="<?php echo MAP;?>"></a></div></td> </tr> </table> index.php <?php include_once("header.php"); add_to_head("<link rel='stylesheet' href='blue.css' type='text/css' media='screen' />");?> Quote Link to comment https://forums.phpfreaks.com/topic/181894-function-add-code-to-head/#findComment-959517 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.