Submit Your Article Forum Rules

Results 1 to 6 of 6

Thread: looking for PHP properties file resources

  1. #1
    Junior Member
    Join Date
    Nov 2003
    Posts
    5

    looking for PHP properties file resources

    hello,

    i'm looking for a resource that would guide me towards recomendations on how to use properties files in PHP.

    I looked around, but couldn't find anything, and my O'reilly book (web database applications with PHP / mySQL) doesn't cover it!:(

    Thanks a lot!

    Lionel

  2. #2
    Junior Member
    Join Date
    Jul 2003
    Posts
    27
    Hi Lionelandre;
    when you say 'properties' files, what exactly do you mean? What purpose does a properties file(s) serve.

    I did not quite understand your question, but I will be happy to help you if you try to rephrase (or maybe I'm so behind I don't know what you're talking about? :) ).

    The only things I can think of right now are:
    1) a 'config' file that configures settings for a PHP script.
    2) php.ini which controls all PHP settings/properties on a server.
    3) a function that return's a file's properties?

    Reply, and I will reply back!
    Yours,
    Jamal

  3. #3
    Junior Member
    Join Date
    Nov 2003
    Posts
    5
    Jamal,

    I'm looking for ways to have all my text messages (such as error messages, all the way to oage headers and titles) in a separate, external file.

    This file stores an ID, with the text string next to it, like so:

    1 = "welcome to acme.org"
    2 = "Your username is empty, please try again."

    and the list goes on.

    in my PHP pages, I'd like to reference this text and have it displayed in line on the page.

    Simple, really, eh ?

    You can also use this to drive internationalization, if you have, say French.properties and English.properties, you swithch the files as the user clicks on the little flag.

    HTH.

    :L

  4. #4
    Junior Member
    Join Date
    Jul 2003
    Posts
    27
    Ah! This time its clear.
    Ok, what you have to do is make seperate files for each language or set of properties like you already mentioned. Now what I want to tell you is that you do not need this syntax:
    1 = "this is the first message"
    2 = "this is the second message"
    in fact, you don't need the ID at all. Heres is why: lets suppose we have a file (text.properties) with the following content:
    Code:
    This is the first line of the file
    This is the second line of the file
    This is the third line of the file
    In your PHP script this is what you would do:
    Code:
    <?php
    $foo = file("text.properties");
    ?>
    The above will take the contents of the file text.properties and put it into an array, therefore:
    $foo[0] = "This is the first line of the file"
    $foo[1] = "This is the second line of the file"
    $foo[2] = "This is the third line of the file"

    Note that it starts at 0, this is the way PHP is built, just like most languages out there. Meaning the first line will have an ID of 0 not 1. If this confuses you, then just leave the first line of the file blank, and simply dont use the variable $foo[0].

    I use this method all the time, and it works great. Use caution however if you allow users to input data into your file (text.properties), if they press enter/return it will insert a new line character (\n) and split the text amongst 2 lines, or more. The solution is simple however:
    $textToInput = str_replace("\n", "", $_POST[formText]);

    Hope this is helpful, and that you understand. I will be more than happy to explain something if there is confusion.

    Yours,
    Jamal

  5. #5
    Junior Member
    Join Date
    Nov 2003
    Posts
    5
    Jamal,

    yeah, this makes complete sense, thanks a lot for that ! :)

    Is there a way, though, to use a specific ID for the message ? my issue with the approach you are suggesting is inserting a line inside the properties file will wreak havoc across the app !!!

    Put it another way .... I'm going to hand the properties file to Marketing people............ 'nuf said?

    Cheers,

    :L

  6. #6
    Junior Member
    Join Date
    Jul 2003
    Posts
    27
    Yes, sometimes I use commas in my files, and explode them. Here's what I mean:
    Lets say $myvar = "1234,This is a sentence.";
    then is you explode it like so

    //Explode at comma (,)
    $myarray = explode(",", $myvar);

    Then $myarray[0] = "1234" and $myarray[1] = "This is a sentence."

    Now the only thing with this is that you cannot have commas in the sentence, or else the array will be bigger. What I usually do is enter a set of characters that is unlikely to be in the sentence itself, such as '[,]'

    like this $myvar = "1234[,]This is a sentence"
    then when you explode, explode at "[,]" instead of ",".

    You can implement it into a file and make it like a flat-file database. The file would have an ID, seperated by a string, and a sentence like so:

    1234[,]This is the first line
    3245[,]This is another line
    4839[,]This is the last line

Similar Threads

  1. Blue Sun Properties
    By CAD in forum Submit Your Site For Review
    Replies: 11
    Last Post: 06-24-2009, 09:14 PM
  2. IIS 5.0 and default log properties
    By ADAM Web Design in forum IT Discussion Forum
    Replies: 2
    Last Post: 11-07-2005, 10:28 AM
  3. Extract all resources from any SWF file
    By Decompile_SWF in forum Flash Discussion Forum
    Replies: 0
    Last Post: 10-15-2005, 04:46 AM
  4. Rhodes Properties
    By Jabber_uk in forum Submit Your Site For Review
    Replies: 6
    Last Post: 10-04-2005, 03:28 AM
  5. Layer Properties
    By WPW_Feedbot in forum Graphics & Design Discussion Forum
    Replies: 0
    Last Post: 09-30-2005, 09:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •