PHP Developer Requied To Write Some String Manupulation Functions

Discussion in 'Programming' started by mintoj, Sep 23, 2008.

  1. #1
    Hi,

    I need a PHP developer who could write me some string manipulation functions. Taking a string, finding a substring based on opening and closing delimiters. Extractng the substring and then returning one element randomly from a delimited substring

    i.e

    "This is {my|your} string"

    Results of the main function call could be:

    "This is my string" or "This is your string"

    The original string may contain mutliple { } sections


    Thanks,

    J
     
    mintoj, Sep 23, 2008 IP
  2. serialCoder

    serialCoder Guest

    Best Answers:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    Hi, are you looking for some sort of templating engine? or just some random text parser?
     
    serialCoder, Sep 23, 2008 IP
  3. salah

    salah Banned

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #3
    Hi, i can do that for you for just 5$.
    Rapidity guaranted
    PM me

     
    salah, Sep 23, 2008 IP
  4. omgitsfletch

    omgitsfletch Well-Known Member

    Messages:
    1,222
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    145
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #4
    I'd like to get in touch with you, I can do this kind of work easily. What's the best way to get in contact?
     
    omgitsfletch, Sep 23, 2008 IP
  5. hdogan

    hdogan Peon

    Messages:
    316
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #5
    Here it is:

    <?php
    function get_random_string($string) {
      $result = $string;
    
      if (preg_match_all("/\{(.*?)}/si", $string, $match, PREG_SET_ORDER)) {
        for ($i = 0; $i < count($match); $i++) {
          $words  = explode("|", $match[$i][1]);
          $random = $words[array_rand($words)];
          $result = str_replace($match[$i][0], $random, $result);
        }
      }
    
      return $result;
    }
    ?>
    PHP:
    Sample usage:

    <?php
    echo get_random_string("I'm {robot|human}. I'm from {earth|venus}.");
    ?>
    PHP:
     
    hdogan, Sep 24, 2008 IP