Author Topic: Need a lesson on PHP  (Read 2076 times)

0 Members and 2 Guests are viewing this topic.

Offline Cholo

  • Hiatus
  • *
  • Posts: 111
  • Respect: +11/-0
  • Gender: Male
    • The Tar Heel Forum
Need a lesson on PHP
« on: September 05, 2010, 11:58:02 PM »
If any of you PHP experts out there can help me out with this, I would be very grateful:




I'm trying to include a piece of text in the <title> of a few html pages across different websites. I want to be able to use PHP to change that text by editing one file instead of having to make edits in the <title>s of several html pages.  The various web page titles would be something like this:



"$500 California Homes"
"$500 Beans & Dip"
"Wheel Barrows - $500"


"$500" is the text I would like to control using PHP.  If anyone can provide a good explanation on how to accomplish this, that would be awesome. Thanks!


Offline bigguy

  • Owner
  • Administrator
  • *
  • Posts: 2652
  • Respect: +38/-0
  • Gender: Male
Re: Need a lesson on PHP
« Reply #1 on: September 06, 2010, 01:15:34 AM »
Maybe Using "require_once" statement in the <title> tags (if you can) and using a include file to change the price on all pages. ??? Does that make sense at all. ???

Like in the title tags you would use something like:

require_once(price.php);
then you would have a file called "price.php" where all the code and text you wanted to change would be. I don't know. I think that would be the only way you could do it but not sure.

Offline Nesa

  • Administrator
  • *
  • Posts: 537
  • Respect: +23/-0
  • Gender: Male
Re: Need a lesson on PHP
« Reply #2 on: September 06, 2010, 07:08:34 AM »
you can do require_once like bigguy said you would make a php with your variable names in it.

eg tag.php
Code: [Select]
<?php

//title variable 
$title "test1";

?>

then use it in your php file
e.g

Code: [Select]
<?php
//variable import
require_once("tag.php");

//title/html code
echo "<html>
<title>Hello 
$title Test</title>
</html>"

?>

Offline bigguy

  • Owner
  • Administrator
  • *
  • Posts: 2652
  • Respect: +38/-0
  • Gender: Male
Re: Need a lesson on PHP
« Reply #3 on: September 06, 2010, 09:46:11 AM »
That's exactly what I was saying. Thanks Nesa. :)

Offline Cholo

  • Hiatus
  • *
  • Posts: 111
  • Respect: +11/-0
  • Gender: Male
    • The Tar Heel Forum
Re: Need a lesson on PHP
« Reply #4 on: September 06, 2010, 02:46:10 PM »
Using this method - do I have to change my web pages to .php pages instead of .html pages? Or is another way to include this php code in the title of an html document?   Thanks as always guys.

Offline bigguy

  • Owner
  • Administrator
  • *
  • Posts: 2652
  • Respect: +38/-0
  • Gender: Male
Re: Need a lesson on PHP
« Reply #5 on: September 06, 2010, 04:22:29 PM »
php can be embedded in html or visa versa. Opening and closing php tags are a must though like Nesa has up there.


Offline Cholo

  • Hiatus
  • *
  • Posts: 111
  • Respect: +11/-0
  • Gender: Male
    • The Tar Heel Forum
Re: Need a lesson on PHP
« Reply #6 on: September 06, 2010, 04:35:09 PM »
Is there a way to do it with less php code in the title area?  For example, SMF and other scripts like Wordpress do something like this:


Code: [Select]
<title>', $context['page_title_html_safe'], '</title>';

There's some kind of text string defined in some other file and this little bit of code is included in the title section.

Offline bigguy

  • Owner
  • Administrator
  • *
  • Posts: 2652
  • Respect: +38/-0
  • Gender: Male
Re: Need a lesson on PHP
« Reply #7 on: September 06, 2010, 04:53:22 PM »
I know what you are saying but I am not sure how they do that.

Offline Cholo

  • Hiatus
  • *
  • Posts: 111
  • Respect: +11/-0
  • Gender: Male
    • The Tar Heel Forum
Re: Need a lesson on PHP
« Reply #8 on: September 06, 2010, 07:59:43 PM »
Hm. Alright thanks bigguy - maybe I'll try out this longer method first and see how that turns out.  Thanks to both of you!

Offline Nesa

  • Administrator
  • *
  • Posts: 537
  • Respect: +23/-0
  • Gender: Male
Re: Need a lesson on PHP
« Reply #9 on: September 06, 2010, 09:40:03 PM »
you can try this:

Code: [Select]
<?php require_once("tag.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />

    <title>Untitled 1 <?php echo $title ?> </title>
</head>

<body>



</body>
</html>

you will need to call the file a php not a html though for the php parts to work.

Offline Cholo

  • Hiatus
  • *
  • Posts: 111
  • Respect: +11/-0
  • Gender: Male
    • The Tar Heel Forum
Re: Need a lesson on PHP
« Reply #10 on: September 18, 2010, 07:35:49 PM »
Hm. That would be a problem for this project.  Maybe that's why SMF, Wordpress, etc. can use that other bit of code. 

Offline ccbtimewiz

  • New Member
  • *
  • Posts: 25
  • Respect: +4/-0
  • Gender: Male
    • Dream Portal
Re: Need a lesson on PHP
« Reply #11 on: October 05, 2010, 02:43:40 AM »
It's all about how you built your website and how you plan on managing your content. You could do it like I do and separate templates and source to an extent and have everything dynamically created.

For example, I have one file called header-template.php, which when called will sport the following syntax:

Code: [Select]
<?php
// @ template file `header` syntax
// @ last edit: september 2, 2010 # 10:29am ccbtimewiz

// dynamically create the head, this will be used in every content file
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
   <meta name="description" content="' 
$content_header['meta_description'] . '" />
   <meta name="keywords" content="' 
$content_header['meta_keywords'] . '" />
   <title>' 
$content_header['title'] . '</title>';

// include JavaScript files if applicable
// note: clean_javascript_includes(&javascript_content (delimited per line), &level_of_filtering ('open' allows all scripts, 'mild' prevents javascript that runs words like "popup" or "alert" often, 'safe' prevents all javascript that does not preg_match the server's uri), num max (the maximum number of scripts allowed on the page)
if (!empty($content['javascript_includes']))
   
clean_javascript_includes($content['javascript_includes'], 'safe'10);

// include Cascading Style Sheet files if applicable
// note: we don't need to be as safe with CSS, but we're running suite similar to "safe" javascripting-- only css from the server's uri can be fetched
if (!empty($content_header['css_includes']))
   
clean_css_includes($content_header['css_includes']);

// we're done here for the most part-- we're not getting into link relevance...
echo '
</head>'
;

// and one more thing, we need to make sure a body is made... in the content specific file.
?>

And then in another php file called credits.php (which is a part of my site, using it as an example, the page is made as so:

Code: [Select]
<?php
// @ source file `about`
// @ last edit: september 1, 2010 # 3:36pm ccbtimewiz

if (function_exists('set_magic_quotes_runtime'))
   @
set_magic_quotes_runtime(0);

error_reporting(defined('E_STRICT') ? E_ALL E_STRICT E_ALL);

$content_header = array(
   
'meta_description' => 'about the team',
   
'meta_keywords' => 'ccbtimewiz.com, about chris, etc',
   
'title' => 'ccbtimewiz.com About',
   
'css_includes' => array(
      
'exterior' => array(
         
'/css/header.css''/css/style.css''/css/index.css',
      ),
      
'interior' => '',
   ),
   
'javascript_includes' => '',
);

require_once(
'../templates/header-template.php');

$content_body = array(
   
// you don't need to see this, you get the picture....
);

require_once(
'../templates/body-template.php');

$content_footer = array(
   
// you don't need to see this either, you get the picture....
);

require_once(
'../template-footer.template.php');

// and that's a wrap.
?>

The way I have it is that templates are completely separated from source itself and the same "bones" are used for each page created, instead of recreating each and every page with html. Makes updating and making new pages a lot easier.
« Last Edit: October 05, 2010, 02:45:50 AM by ccbtimewiz »

Offline bigguy

  • Owner
  • Administrator
  • *
  • Posts: 2652
  • Respect: +38/-0
  • Gender: Male
Re: Need a lesson on PHP
« Reply #12 on: October 05, 2010, 06:56:08 AM »
Glad to see ya ccbtimewiz. Nice of you to drop in. :)

Offline ccbtimewiz

  • New Member
  • *
  • Posts: 25
  • Respect: +4/-0
  • Gender: Male
    • Dream Portal
Re: Need a lesson on PHP
« Reply #13 on: October 06, 2010, 04:35:56 AM »
No problem. :P

Still miss SMFH from time to time and always enjoy stopping by here once in a while when I have free time. :D

Offline bigguy

  • Owner
  • Administrator
  • *
  • Posts: 2652
  • Respect: +38/-0
  • Gender: Male
Re: Need a lesson on PHP
« Reply #14 on: October 06, 2010, 09:41:13 AM »
The spirit of SMFH lives on in this site. Drop by more dude. :)

Offline Cholo

  • Hiatus
  • *
  • Posts: 111
  • Respect: +11/-0
  • Gender: Male
    • The Tar Heel Forum
Re: Need a lesson on PHP
« Reply #15 on: October 13, 2010, 01:29:34 PM »
Thanks again to all you guys for the help.  Nice to see you too ccb. I haven't gotten the time to install Dream Portal yet, but I'm working on a project I'm thinking of using it on. 

Anyway .. in the case where I'm using php include to include a php or html file into an html file, does the included file need to look a certain way?  ie, does it need to have html or php tags? 

Right now I'm trying to include a bit of code from another file that is located in a separate directory on the same server into an html file and it's not working. 

Offline ccbtimewiz

  • New Member
  • *
  • Posts: 25
  • Respect: +4/-0
  • Gender: Male
    • Dream Portal
Re: Need a lesson on PHP
« Reply #16 on: October 13, 2010, 02:35:31 PM »
Show me what you're doing

Offline Cholo

  • Hiatus
  • *
  • Posts: 111
  • Respect: +11/-0
  • Gender: Male
    • The Tar Heel Forum
Re: Need a lesson on PHP
« Reply #17 on: October 13, 2010, 03:59:30 PM »
I'm adding a live chat widget to a bunch of websites (which are all on the same server). The chat will be "sliding out" using a bit of javascript. 

I placed a single javascript file into a directory on one of the main websites and all the other satellite websites are linking to that javascript file in the <head> section.

What I can't figure out is how to do the same thing with the following bit of html code.  All of the websites I am dealing with have html extensions and need to stay that way.

Code: [Select]
<div class="slide-out-div">
            <a class="handle" href="http://link-for-non-js-users.html">Live Chat Support[/url]
            <p><!-- Beginning of meebo me widget code.
Want to talk with visitors on your page? 
Go to http://www.meebome.com/ and get your widget! -->
<embed src="http://widget.meebo.com/mm.swf?saetzTIAkl" type="application/x-shockwave-flash" width="280" height="275"></embed>
            </p>
            <p><center>- - - - - - - - - - - - - - - - - - - - - -</center>
            [br /]
            If prompted, you must run the ActiveX plugin for the chat to function. If we are away or you are having technical difficulties, please feel free to contact us using the "Get Started Now" form to the right or call our office by phone at (518) 465-2211.</p>
        </div>

 ??? Seems like it should be so simple and I'm sure it is, but I'm stuck. Thanks for the help.

Offline butchas

  • Hosted Member
  • *
  • Posts: 112
  • Respect: +8/-0
  • evil php programmer & mac, ah errr... cat lover
    • East Coast Rolling Thunder car club
Re: Need a lesson on PHP
« Reply #18 on: October 14, 2010, 11:35:51 PM »
Not sure what you want  but...

Code: [Select]
<?php
echo ' <div class="slide-out-div">';
echo 
' <a class="handle" href="http://link-for-non-js-users.html">"Live Chat Support"</a><p>';
/* Beginning of meebo me widget code.
Want to talk with visitors on your page?  
Go to http://www.meebome.com/ and get your widget! */
echo ' <embed src="http://widget.meebo.com/mm.swf?saetzTIAkl" type="application/x-shockwave-flash" width="280" height="275"></embed>
            </p>
            <p><center>'
- - - - - - - - - - - - - - - - - - - - - -'</center> 
            <br />
            " If prompted, you must run the ActiveX plugin for the chat to function. If we are away or you are having technical difficulties, please feel free to contact us using the "Get Started Now" form to the right or call our office by phone at (518) 465-2211."</p>
        </div>'
;
?>

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal