Announcement

Collapse
No announcement yet.

Some clever PHP snippets for Version 8

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Some clever PHP snippets for Version 8

    I start this thread becasue of some recent interest in V8+PHP.

    Please, post any php snippets and how to use them briefly in this thread.

    i'll start us off:

    in actinic_main.php
    PHP Code:
      function AutoLink($txt){
    return 
    preg_replace'/(http|ftp)+(s)?:(\/\/)((\w|\.)+)(\/)?(\S+)?/i''<a href="\0">\4</a>'$txt ); 
      } 
    in your v8:
    PHP Code:
    <actinic:block php="true" >
        
    $thistext '<actinic:variable encoding="perl" name="FragmentText"/>';
        
    $thistext str_replace('!!<','',$thistext);
        
    $thistext str_replace('>!!','',$thistext);
        echo 
    AutoLink($thistext);
    </
    actinic:block
    this example uses FragmentText. It will strip out line breaks and create links automagically, when you type them in your input, saving you the time of creating them manually.

    #2
    php create correct sentence case v8

    in actinic main php:
    PHP Code:
    function sentence_cap($impexp$sentence_split) {
        
    $textbad=explode($impexp$sentence_split);
        
    $newtext = array();
        foreach (
    $textbad as $sentence) {
            
    $sentencegood=ucfirst(strtolower($sentence));
            
    $newtext[] = $sentencegood;
        }
        
    $textgood implode($impexp$newtext);
        return 
    $textgood;

    examples of usage:
    PHP Code:
    $text "this is a sentence. this is another sentence! this is the fourth sentence? no, this is the fourth sentence.";
    $text sentence_cap(". ",$text);
    $text sentence_cap("! ",$text);
    $text sentence_cap("? ",$text);

    echo 
    $text// This is a sentence. This is another sentence! This is the fourth sentence? No, this is the fourth sentence. 

    Comment


      #3
      force breaks every X characters

      PHP Code:
      $text "The quick brown fox jumped over the lazy dog.";
      $newtext wordwrap($text20"<br />\n");

      echo 
      $newtext
      Inserts a break into the string at intervals.

      Comment


        #4
        pull data from any website to include

        PHP Code:
        <actinic:block php="true" >
            echo 
        file_get_contents("http://site-i-like.com/somefile.txt");
        </
        actinic:block
        take data from anywhere and include it in your site as static text.

        take care. you could easily mess up your page rendering with this one, if the file isnt what you expected.

        Comment

        Working...
        X