PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, June 29, 2022

[FIXED] How can show only the characters after dash ( - )?

 June 29, 2022     character, foreach, smarty     No comments   

Issue

I have the title ( Architectural_Garden_Hardware-Switch Plates & Outlet Covers )

But i whant show only the characters after dash ( - ) like ( Switch Plates & Outlet Covers )\

How can do that?

{foreach from=elements item=birds}
   <option value="{$birds}">{$birds}</option>
/foreach}

Solution

You should use strpos and substr as in the following example:

{assign var="var" value=" ( Architectural_Garden_Hardware-Switch Plates & Outlet Covers )"}
{assign var="pos" value=$var|strpos:"-"}
{$var|substr:($pos+1)}

You could also use shorter syntax:

{assign var="var" value=" ( Architectural_Garden_Hardware-Switch Plates & Outlet Covers )"}
{$var|substr:($var|strpos:"-"+1)}

so in your case you could probably use:

{foreach from=elements item=birds}
   <option value="{$birds|substr:($birds|strpos:"-"+1)}">{$birds|substr:($birds|strpos:"-"+1)}</option>
{/foreach}


Answered By - Marcin NabiaƂek
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing