Object's fontSize attribute not changing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gomescoder
    New Member
    • Jun 2007
    • 2

    Object's fontSize attribute not changing

    HI TSDN Pals,


    I am trying to create an object to modify its colour, size, message attributes on the fly using OOP concept...

    Everything works fine with this code but the problem is the font size is not changing. I have highlighted the problem area in the below snippet.

    // Start of the Snippet
    -------------------------------
    [code=php]
    class theme{

    var $fontColour;
    var $fontSize;
    var $amessage;

    function __construct($fo ntColour,$fontS ize){ // attribute intialization

    $this->fontColour=$fo ntColour;
    $this->fontSize=$font Size;

    }

    function accessMessageFe tch() { // amessage attrirbute fetching from file

    $fd=fopen("incl udes/amessage.inc", "r+") or die ("Can't open the file amessage.inc");
    $fstring =fread($fd, filesize("inclu des/amessage.inc")) ;
    $this->amessage=$fstr ing;
    fclose($fd);

    }

    function accessDisp(){ // display function

    /*************** *************** *************** ****
    * Problem Area:
    *************** *************** *************** ****/
    echo "<span><fon t color=/'".$this->fontColour."/' size=/'".$this->fontSize."/'>".$this->amessage."</font></span>"; // Problem area

    }

    } // end of class

    $themeSetting=n ew theme('#3671AD' ,+2);
    $themeSetting->accessMessageF etch();
    $themeSetting->accessDisp() ;[/code]

    [Please use CODE tags when posting source code. Thanks! --pbmods]

    Please advice...
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, gomescoder. Welcome to TSDN!

    Try adding a style attribute to your span instead of creating a (deprecated) font tag:

    [code=php]
    echo <<<EOT
    <span style="color:{$ this->fontColour};fo nt-size:{$this->fontSize};">{$ this->amessage}</span>
    EOT;
    [/code]

    Comment

    • gomescoder
      New Member
      • Jun 2007
      • 2

      #3
      Hi Pbmods,

      Your solution worked thatz great

      additionally i have learnt that you need to pass the font-size value along with the suffix 'px'

      From my previous posting there is a bug in line 34.

      Code: ( Php )

      34: $themeSetting=n ew theme('#3671AD' ,+2);

      --END OF CODE

      The above line 34 should be written as

      34: $themeSetting=n ew theme('#3671AD' ,'20px'); // Change in the Font-size argument


      Thanks Pbmods

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, gomescoder.

        Originally posted by gomescoder
        Your solution worked thatz great
        Excellent. You can leave the money on the table. Hah, just kidding. Glad to hear you were able to get it working.

        Thanks for posting your solution in case other members run into the same problem.

        Good luck with your project. Post back anytime if you need anything!

        Comment

        Working...