Announcement

Collapse
No announcement yet.

PHP to reverse Product Reference

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

    PHP to reverse Product Reference

    I realise that this must sound like an odd thing to do but I want to display my none Actinic generated Product Reference in reverse order on the web page.

    EG Real Product Reference = ABC1234
    Display Product Reference = 4321CBA

    I realise I need to put this in a PHP Block but have had no luck trying to modify any of the example in the AUG or Forum
    Unusual Silver Jewellery
    Giftmill - Unusual Gifts
    Crystal Healing Jewellery
    Steampunk Jewellery

    #2
    Check out http://php.net/manual/en/function.strrev.php

    HTML Code:
    echo strrev("Hello world!"); // outputs "!dlrow olleH"


    Bikster
    SellerDeck Designs and Responsive Themes

    Comment


      #3
      Thanks for that Jont. Have bookmarked the site for future reference
      Unusual Silver Jewellery
      Giftmill - Unusual Gifts
      Crystal Healing Jewellery
      Steampunk Jewellery

      Comment


        #4
        For any future searchers here is the final code.

        If I ever work out how to keep the first three letters the same and just reverse the last four digits I will post back.

        Code:
        <actinic:block php="true" type="PriceList" >
        	     echo strrev("<actinic:variable name="ProductReference" />");
             </actinic:block>
        Unusual Silver Jewellery
        Giftmill - Unusual Gifts
        Crystal Healing Jewellery
        Steampunk Jewellery

        Comment


          #5
          how to keep the first three letters the same and just reverse the last four digits
          Here you go:
          Code:
          <actinic:block php="true">
           $ref = '<actinic:variable name="ProductReference" encoding="perl" selectable="false" />';
           echo substr($ref, 0, 3) . strrev(substr($ref, 3));
          </actinic:block>
          Note that I removed the type="PriceList" bit of code as it seems erronous and redundant.
          Norman - www.drillpine.biz
          Edinburgh, U K / Bitez, Turkey

          Comment


            #6
            Thanks as ever Norman -code works perfectly.

            Code:
            $ref = '<actinic:variable name="ProductReference" encoding="perl" selectable="false" />';
            Would I be right in thinking that $ref is a variable you have created and loaded the Product Reference into it.

            Code:
            echo substr($ref, 0, 3) . strrev(substr($ref, 3));
            echo sends what is following it to the page
            The first substr starts as position 0 and returns 3 characters
            The second substr starts at position 3 and returns the rest of the characters and strrev reverses this part.

            Is that correct in simple terms?
            Unusual Silver Jewellery
            Giftmill - Unusual Gifts
            Crystal Healing Jewellery
            Steampunk Jewellery

            Comment


              #7
              Yes. That's exactly what it does.
              Norman - www.drillpine.biz
              Edinburgh, U K / Bitez, Turkey

              Comment

              Working...
              X