SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist
    Join Date
    Oct 2001
    Location
    Texas
    Posts
    598
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smarty string replace

    I am trying to replace part of a string that is within a smarty template. Any text before and including a semicolon with nothing.

    Example string
    "Name: Info"
    Result
    "Info"


    Any help would be appreciated.

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    http://uk3.php.net/strstr

    PHP Code:
    $string trim(strstr(':'$string)); 

  3. #3
    SitePoint Evangelist
    Join Date
    Oct 2001
    Location
    Texas
    Posts
    598
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, but is this possible to do to a variable inside of a Smarty template?

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,147
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    {$string|replace:'Name: ':''}

    You can also overload smarty with your own modifiers which can be a very powerful solution.

    Also when inside a Smarty template it is possible to move into php using {php} tags.

    {php}
    $this->assign('string',str_replace($this->get_template_vars('string'),'Name: ',''));
    {/php}

    {$string}

    You can than get the variable your after using get_template_vars() method and reassign it directly to the template before printing it.

  5. #5
    SitePoint Evangelist
    Join Date
    Oct 2001
    Location
    Texas
    Posts
    598
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "Name:" however changes... Name is a variable that ends with :. Trying to remove the Name and :

  6. #6
    SitePoint Evangelist
    Join Date
    Oct 2001
    Location
    Texas
    Posts
    598
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I decided to just modify the php.

    trim(substr(strstr($name, ':'),1));


Bookmarks

Posting Permissions

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