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

0 Members and 1 Guest 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. :)

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal