Announcement

Collapse
No announcement yet.

PHP help please

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

    PHP help please

    Can anyone please help me create some PHP code?

    I'm trying to create some simple PHP code to use in an Actinic layout that does the following:

    Takes the Actinic variable 'ProductName', replaces the spaces in the name with another manually created site variable called 'SpacerChar'.

    Example:-

    Input variables:
    ProductName = My New Red Widget
    SpacerChar = -

    PHP Output:
    My-New-Red-Widget


    Any help greatly appreciated.

    #2
    I believe I have this working as follows (please correct if I'm wrong - but it seems to work):
    Code:
    <actinic:block php="true" >
    $sProdName = '<actinic:variable encoding="perl" name="ProductName" selectable="false" />';
    $sSpacerChar = '<actinic:variable name="SpacerChar" encoding="perl" selectable="false" />'; 
    $sProdName = str_replace (" ", $sSpacerChar, $sProdName); 
    echo $sProdName;
    </actinic:block>
    I intend to use this to create relative links from a duplicate product to the main product (one product per page) where the product name is the same as the section page name for the single product with execption that the spaces need to be removed and replaced by another character (in my case a - but could be _).

    Reference this thread from around post 34:
    http://community.actinic.com/showthr...t=26482&page=3

    Comment


      #3
      Code looks OK. However I tend to use encoding="perl" selectable="false". E.g.

      $sSpacerChar = '<actinic:variable name="SpacerChar" encoding="perl" selectable="false" />';

      wherever I use a variable within quotes in PHP.
      Norman - www.drillpine.biz
      Edinburgh, U K / Bitez, Turkey

      Comment


        #4
        Thanks for that Norman. I've updated the code above to reflect this.

        Comment


          #5
          You can actually set this up in the variable definition but I think it's easier to put it in the code as inexplicable things can happen if you forget it in the def'.
          Norman - www.drillpine.biz
          Edinburgh, U K / Bitez, Turkey

          Comment


            #6
            Duncan - having only got to hour 4 of the PHP Book as delivered by Santa this Christmas I am amazed to find I can just about understand the code you have created above..... but where/how is the "-" character being defined with the Actinic variable "SpacerChar" ... is this simply declared inside Actinic itself?


            Bikster
            SellerDeck Designs and Responsive Themes

            Comment


              #7
              I created SpacerChar as a new variable and selected Place of Setting to be 'Site'. Then you can set it in Site Options - Properties. In my site under developement I decided to create all my page names with '-' as the word separator instead of the default '_' (we'll see how G likes that later?!). So this variable allows you to select the character you want to use.

              I have a PHP book also but just dive in when needed - never seem to find time to read (too much time spent on the forum perhaps!). Using PHP in Actinic is going to open up a whole new world of possibilities.

              Comment


                #8
                Blimey - I did understand it not bad after 4 nights reading whilst Mrs Jont watches corrie and Jonty Junior attacks me with Stars Wars lego.

                Of course understanding it and creating it from scratch is a whole different game....


                Bikster
                SellerDeck Designs and Responsive Themes

                Comment


                  #9
                  And don't forget to scrutinise all those patches that are posted here and in the Advanced Guide. They contain lots of snippets that are helpful.

                  Also don't mind re-using existing code if it's been publicly posted. You'll find various bits in my code that are straight out of my PHP book or the PHP help file (that's one link that's always on my desktop).
                  Norman - www.drillpine.biz
                  Edinburgh, U K / Bitez, Turkey

                  Comment


                    #10
                    Originally posted by NormanRouxel
                    And don't forget to scrutinise all those patches that are posted here and in the Advanced Guide.
                    Sadly enough I have been doing this - it like suddenly being able to understand Chinese - making more and more sense each time I read them


                    Bikster
                    SellerDeck Designs and Responsive Themes

                    Comment

                    Working...
                    X