Results 1 to 6 of 6

Thread: PHP Syntax Inquiry - Quotes Module

  1. #1
    Join Date
    Jul 2009
    Posts
    17

    Default PHP Syntax Inquiry - Quotes Module

    Hello,

    I am attempting to change the way the file name for the generated PDF quote is written. I have made most of the changes, but I am stuck on one thing. Here is an example of how it currently is:

    Quotation_12345-CustomerOfficeABC.pdf

    I would like to know the syntax that would be needed to create spaces in the company name. For example:

    Quotation_12345-Customer Office ABC.pdf

    Here is what my syntax looks like in standard.php:

    PHP Code:
    $GLOBALS['log']->info("Quote layout view: Standard");
    $quotesub preg_replace("#[^A-Z0-9\-_\.]#i",""$focus->name);
    $filename = ($focus->quote_num);
    if (!empty(
    $quotesub)) {
        
    $filename .= "-{$quotesub}";
    }
    $filename $mod_strings['LBL_PROPOSAL']. "_{$filename}.pdf"
    I have tried backslash characters in the preg_replace function, but to no avail.:
    PHP Code:
    $quotesub preg_replace("#[^A-Z0-9\-_\.]#i","(something goes here)"$focus->name); 
    Nothing I do works. If I just leave a space between the parenthesis it only shows the first word in the customer name and drops the rest and the file extension. I know this is probably really simple, so any help on how to do this would be great. Thanks!

  2. #2
    johanw is offline Member
    Join Date
    Feb 2009
    Posts
    12

    Default Re: PHP Syntax Inquiry - Quotes Module

    I dont really understand your question.

    Do you have a problem with the regular expression?

    to replace everything that doesn't match spaces, letters and dots and - characters you should have something like this.


    PHP Code:
    $quotesub preg_replace("#[^\w\s-\.]#",""$focus->name); 
    Last edited by johanw; 2009-09-25 at 07:55 AM. Reason: PHP syntax colororing is nice! :P
    ---
    Johan Westin
    Redpill Linpro AB - Changing the game

  3. #3
    Join Date
    Jul 2009
    Posts
    17

    Default Re: PHP Syntax Inquiry - Quotes Module

    I guess I just need to know what character represents a space in text. For example, if I write the expression as:

    PHP Code:
    $quotesub preg_replace("#[^\w\s-\.]#"," "$focus->name); 
    Then file name is "Quotation_12345-General"

    I need it to be "Quotation_12345-General Motors headers.pdf"

    Notice that the first file name is half missing. Only the first word in the quote subject shows up. Everything after that doesn't show up. If I remove the preg_replace from the expression then it still does the same thing. Does this explanation help explain what I'm trying to do?

  4. #4
    johanw is offline Member
    Join Date
    Feb 2009
    Posts
    12

    Default Re: PHP Syntax Inquiry - Quotes Module

    Quote Originally Posted by spencermitchell View Post
    I guess I just need to know what character represents a space in text. For example, if I write the expression as:

    PHP Code:
    $quotesub preg_replace("#[^\w\s-\.]#"," "$focus->name); 
    Then file name is "Quotation_12345-General"

    I need it to be "Quotation_12345-General Motors headers.pdf"

    Notice that the first file name is half missing. Only the first word in the quote subject shows up. Everything after that doesn't show up. If I remove the preg_replace from the expression then it still does the same thing. Does this explanation help explain what I'm trying to do?
    When i run the code only letters, whitespaces and dots are keept.

    \w = word charachter
    \s = whitespace character

    reg exp quick reference.
    http://www.addedbytes.com/cheat-shee...s-cheat-sheet/
    ---
    Johan Westin
    Redpill Linpro AB - Changing the game

  5. #5
    goko is offline Sugar Community Member
    Join Date
    Apr 2008
    Location
    Stockholm, Sweden
    Posts
    69

    Default Re: PHP Syntax Inquiry - Quotes Module

    Hi spencermitchell

    It's not clear what you want to accomplish exactly.

    Your first example gave me the impression that you wanted to transform all occurrances of a lower case letter immediately followed by an upper case letter with lower case letter + space + upper case letter
    but then you have an example and says:
    I need it to be "Quotation_12345-General Motors headers.pdf"
    It's not clear what you had from the beginning there...

    To solve the first you can try this:
    PHP Code:
    $s "Quotation_12345-CustomerOfficeABC.pdf";

    echo 
    "$s\n";

    $pattern='/([a-z])([A-Z])/';
    $repl '$1 $2';
    $s_with_added_spaces preg_replace($pattern,$repl$s);

    echo 
    "$s_with_added_spaces\n"
    Last edited by goko; 2009-09-28 at 11:29 AM. Reason: clarifications

    Göran Korsgren

  6. #6
    Join Date
    Jul 2009
    Posts
    17

    Default Re: PHP Syntax Inquiry - Quotes Module

    Goran,

    Sorry I am being so confusing. I think I am explaining my issue in a way that is making things harder. All I want to do is have the file name read as follows:

    "quotation"_"quote number"-"quote subject".pdf

    In other words, I want the file name to read, "Quotation" followed by an underscore (_), followed by the quote number, followed by a dash (-), followed by the quote subject (i.e. Company ABC Widget). I have gotten everything to work properly except for the "quote subject".pdf part. Hope this helps. If not, I can always just write the function as follows:

    PHP Code:
    $GLOBALS['log']->info("Quote layout view: Standard");
    $quotesub preg_replace("#[^A-Z0-9\-_\.]#i","_"$focus->name);
    $filename = ($focus->quote_num);
    if (!empty(
    $quotesub)) {
        
    $filename .= "-{$quotesub}";
    }
    $filename $mod_strings['LBL_PROPOSAL']. "_{$filename}.pdf"
    This will output:

    "quotation"_"quote number"-"quote_subject".pdf

    Thanks!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Duplicating Quotes module ?
    By Liior in forum Developer Help
    Replies: 4
    Last Post: 2009-05-28, 10:04 AM
  2. MODULE: Products & Quotes
    By ftreml in forum Downloads
    Replies: 99
    Last Post: 2009-01-27, 03:35 PM
  3. Need Developer for Quotes Module
    By anitian in forum Classifieds
    Replies: 9
    Last Post: 2008-11-08, 03:37 PM
  4. Quotes Module Usability
    By chad.hutchins in forum General Discussion
    Replies: 1
    Last Post: 2007-12-08, 04:03 PM
  5. Customizing Quotes Module
    By pmeisner in forum Developer Help
    Replies: 2
    Last Post: 2006-02-09, 05:55 PM

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
  •