PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Johannes  >  Smileys To IMG  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example file
Class: Smileys To IMG
Replace smiley text with the respective image tags
Author: By
Last change:
Date: 11 years ago
Size: 1,815 bytes
 

Contents

Class file image Download
<html>
    <head>
    </head>
    <body>
   
    <h1>1) Create an object</h1>
    <p>The only thing you have to do is making an instance of the class, for example: </p>
    <pre>
    $smiley = Smiley2IMG::getInstance('smiley.txt', 'images');
    </pre>
    <p>
    The first parameter is the configuration file, which maps the corresponding images files to the smiley codes.<br/>
    The second parameter is the basepath (clientside) of all the images.

    </p>
   
    <h1>2) Usage</h1>
    <p>Use the parse method to replace smiley codes.</p>
    <pre>
    $str = "
        :( :[ :-(
                                    <br/>
        :-O :-o :o
                                    <br/>
        >:-) 3:) >:)
                                    <br/>
       
        :) :-) :]
                                    <br/>
        Enjoy using this class! :)
    ";
    echo $smiley->parse($str);
    </pre>
   
   
    <h1>3) Configuration file</h1>
    <p>The the configuration file (based on the <a target="_blank" href="http://php.net/manual/de/function.parse-ini-file.php">parse_ini_file()</a> function of php) has the following structure:</p>
        <pre>
       
    [smile]
        file=smile.gif
        codes[] = ":)"
        codes[] = ":-)"
        codes[] = ":]"
        codes[] = "=)"
           
    [grin]
        file=grin.gif
        codes[] = ":-D"
        codes[] = ":D"
        codes[] = "=D"
       
    [{emocionname_can_be_everything}]
        file={filename.extension}
        codes[] = "{smiley_code}"
        codes[] = "{another_smiley_code}"
        codes[] = "{another_smiley_code2}"
       
        </pre>


<h1>4) Example</h1>












<?php
require_once('smiley.php');

$smiley = Smiley2IMG::getInstance('smiley.txt', 'images');
$smiley_no_config = Smiley2IMG::getInstance('thisfiledoesnotexist.txt', 'images');

$str = "
    :( :[ :-(
   
                                <br/>
   
    :-O :-o :o
   
                                <br/>
   
    >:-) 3:) >:)
   
                                <br/>
   
    :) :-) :]
   
                                <br/>
   
    Enjoy using this class! :) :D :-)
    <br/><br/>
   
"
;


echo
$smiley_no_config->parse($str);

echo
$smiley->parse($str);

?>




















    </body>
</html>


For more information send a message to info at phpclasses dot org.