Help with php and regular expressions

I am making a package and would like php to execute sed - command during setup (when user goes to installation php page and submits info). Like this:
exec("sed -i 's|^.*$db_host.*$|$db_host="$HOST";|' config.php");
exec("sed -i 's|^.*$db_user.*$|$db_user="$IPUSER";|' config.php");
exec("sed -i 's|^.*$db_password.*$|$db_password="$IPUSERPASS";|' config.php");
exec("sed -i 's|^.*$db_name.*$|$db_name="$DBNAME";|' config.php");
exec("sed -i 's|^.*$url_base.*$|$url_base="$URLBASE";|' config.php");
Apparently something is wrong with escapes because sed never gets any matches that it would replace.

phrakture wrote:
mmgm wrote:
cactus wrote:and there is no reason to stick a .* on the front of the regexp. Just make sure the variables have no blank space at the start of the line in front of them.
Making sure you have no blank space before the variable is quite a demand for people obsessed with tabbing, like me.
I swear, if my tab key ever breaks, I'm gonna start smashing things.
I'm such a clean-code-whore.
but this is a config file... do you really tab out your config files?
Config files are usually ment to be human-readable. This is why they usually contain comments and such. Tabbing makes code more readable and therefore I find it usefull in any file which contains text of any sort. In the end, it's going to make your life a whole lot easier.

Similar Messages

  • Help with Java and Regular Expression

    Hello,
    I have one line of Java and regular expression that I got from the web :
    String[] opt;
    opt = line.split("\\s+(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
    If "line" contains :
    1 "Hello World"
    this code would give me :
    opt[0] : 1
    opt[1] : "Hello World"
    which is almost what I would like to do except for the double quotes. I wonder if someone could please help me change the regular expression so that it would return :
    opt[0] : 1
    opt[1] : Hello World
    Thank you and Best Regards,
    Chris

    It looks to me like this is a line from a space delimited file so you should use one of the free CSV parsers such as http://opencsv.sourceforge.net/ . These will handle the quotes properly even if a field actually contains a quote.

  • [solved] Need a little help with sed and regular expressions

    Hello!
    I am shure this is something easy for most of you
    I want to make a script, which converts filenames of my ripped MP3s (replaces '_' with spaces, removes leading track numbers...)
    But I have some problems:
    j=$(echo $j | sed 's/_\+/ /g')
    j=$(echo $j | sed 's/^[0-9]{0,3}//g')
    j=$(echo $j | sed 's/[^ ]-[^ ]/ - /g')
    j=$(echo $j | sed 's/_\+/ /g') << this is working fine (converts all "_" to spaces)
    j=$(echo $j | sed 's/^[0-9]{0,3}//g') << is NOT working, why??
    For Example in "01-somebody_feat_someone-somemusic.mp3" the leading "01" number is NOT being removed..
    j=$(echo $j | sed 's/[^ ]-[^ ]/ - /g') << how can I insert spaces before and after the "-"?
    So that "someone-somemusic" becomes "someone - somemusic" (but only where "-" is surrounded by letters)
    Last edited by cyberius (2011-07-27 18:50:54)

    For sed, you must escape { and } to use them as you want (just slap a \ before them).
    For the last expression, capture the letter before/after the dash -- use \( and \) -- and then substitute it for something like "\1 -" and then "- \1". You'll want to split this into two pieces, one for the front and one for the back so you can get "somemusic -someband" the way you want without a bunch of cases.
    Edit: Or, you could just do a replace for "-" to be " - " and then have another expression to reduce spaces. I see you've used \+ before, so I'm guessing you can figure that out
    Also, sed has the -e switch so you can do multiple different expressions with one invocation.
    Also (also), have you looked into something like Picard with automatic track renaming? You can even customize how they are renamed.
    Edit (2): Also^3, check out prename. There are different versions, ones which use PCRE and ones that use other standards, but it is for renaming files based on regular expressions, which is what you're doing. In any case, you might want to put you script into the User made scripts thread when you feel more comfortable and get some more critiquing, if you're interested.
    Last edited by jac (2011-07-26 23:13:27)

  • Help with PHP and

    Notice: Undefined index: product_style in/var/www/html/qualitycarton.com/cw3/admin/ProductForm.php on line 509
    This is what I get when I tried to add a field to my cartweaver database.
    If you don't know cartweaver it's basically a dreamweaver extension for ecommerce. I wanted to add some fields to the product table in the database. I successfully added the fields, added the input fields on the productform.php and the necessary scripts to productaction.php, I also used
    $yourvariable = "";
    if (isset($_POST['yourvariable'])) {
       $yourvariable = $_POST['yourvariable'];
    in the form but for some reason I still have an undefined index. Please help!
    thanks,
    Ian

    You may get a quicker answer from Cartweaver's newsgroups.
    http://www.cartweaver.com/support/
    They're usually quite prompt and helpful.

  • Need help with php and flash

    Hi,
    hopefully anyone can help me out here I am working on a site
    that has part flash and html in it. I am using php to dynamically
    pull in the flash files from an includes folder. In doing so I have
    uploaded everything to our preview server where I tested the site.
    It works in firefox but not in the ie browsers, I thought this had
    to do with active control, so I downloaded the extension but
    nothing happened, still it works in firefox and not ie either 6 or
    7. t
    click
    here to view the site I am working on. If you have suggestions
    please let me know. I have attached the code as well for one of the
    flash animations.
    Thanks

    Looking at the source of your page, I note that you missed a
    couple lines in the AC_FL_RunActiveContent embed. These 2 lines go
    in the head of the page.
    <script language="javascript"> AC_FL_RunContent = 0;
    </script>
    <script src="AC_RunActiveContent.js"
    language="javascript"></script>

  • Help with PHP and CSS links (&mysql results)

    Hi
    Hope someone can help.  I have a column in a mysql5 database that records if an advert is 'featured' or not with 'yes' or 'no' in the database fields.
    I'm dynamically creating a list of adverts using php5 and DWCS3 where each ad comprises several table rows and these are wrapped up in a repeat region (rather than one table row per ad title) and I'd like to highlight the background of the 'featured' advert using  link to a style class eg so that the 'featured' ads have a different background colour to the rest of the ads listed.
    I've got the following code so far, which highlights the adverts but it does this for all of them (featured and non-featured).
    The 'advertpagetabletext' class is the standard (default) rule applied to non-featured adverts.  The "advertfeatured" class is the new background colour.
    Can anyone point me in the right direction / comment on the code below?
    Thanks in advance,
    M
    <?php $featured = $row_listJobs(['job_featured']; ?>
    <?php do { ?>
    <table width="100%" border="0" cellpadding="3" cellspacing="0"<?php if($featured == y) {echo 'class="advertfeatured"'; } else {echo 'class="advertpagetabletext"'; } ?>>
    <tr>
    <td ....rest of table and rows etc etc...

    Ahh, penny drops,
    From what I can see the class is coming through as "advertfeatured" on all of the ads - so it seems to be ignoring the fact that some are not featured / and doesn't revert to the other class for the second ad listing.
    //This is for a featured advert //
    Job Title: Viticulturalist
    etc etc //This is for a nonfeatured advert//
    Job Title: Cellar Hand
    Job Category: �i�o
            <tr

  • Help with PHP and FLEX integration

    Hello i was wondering how to use php sessions with flex, i
    need a way to have secure connections between flex and php.
    I am using a script i made to pass mysql commands/results
    between them, and i am currently passing the php session id with
    the transactions. But if anyone gets a hold of a valid php session
    id then they will be able to use it. Possibly using flex server to
    have secure transactions?
    If i host both the flex created swf and the php file on a
    https server will it "talk" securely?
    thanks lots

    You may get a quicker answer from Cartweaver's newsgroups.
    http://www.cartweaver.com/support/
    They're usually quite prompt and helpful.

  • Help with PHP and FTP

    Hi !
    I am trying to use the ftp support in php to move files from one server(A) to another(B). We have secure ftp connection to the other server(B) I am trying to connect from PHP script and ftp_connect( ) is not working.
    1 )Is there a way I can overwrite this function in order
    to connect using sftp ??
    2 ) Also if I run the phpinfo, how would i know which
    port php is using for ftp_connect ??
    3 ) Can I use ftp_ssl_connect( ) ??
    Please help
    Thanks in advance

    You may get a quicker answer from Cartweaver's newsgroups.
    http://www.cartweaver.com/support/
    They're usually quite prompt and helpful.

  • Update on help with PHP to send an email

    On Jan 9th Iasked for help Asking for help with PHP to send an email wanting to send myself an email when a particular web page was opened.The group gave me lots of ideas / suggestions but unfortunately I was not able to make it work the way I wanted. But.. with perseverance.. made it work. The original PHP code I wanted to use was:
    <?php mail('[email protected]','Subject of the e-mail','This is the body of the e-mail!'); ?>
    After much trial and error. this is what I found works.. for me at any rate. My log in sets a cookie that welcomes my user back by name so I ended up using that information with this:
    <?php
    if (isset($_COOKIE["last_in"])) {
      $user = $_COOKIE["last_in"];
    mail('[email protected]','News Page',"$last_in");
    ?>
    Again, thank you for all the help with my initial question.. there are a multitude of ways to accomplish a task, and for me this is the one I was looking for.

    On Jan 9th Iasked for help Asking for help with PHP to send an email wanting to send myself an email when a particular web page was opened.The group gave me lots of ideas / suggestions but unfortunately I was not able to make it work the way I wanted. But.. with perseverance.. made it work. The original PHP code I wanted to use was:
    <?php mail('[email protected]','Subject of the e-mail','This is the body of the e-mail!'); ?>
    After much trial and error. this is what I found works.. for me at any rate. My log in sets a cookie that welcomes my user back by name so I ended up using that information with this:
    <?php
    if (isset($_COOKIE["last_in"])) {
      $user = $_COOKIE["last_in"];
    mail('[email protected]','News Page',"$last_in");
    ?>
    Again, thank you for all the help with my initial question.. there are a multitude of ways to accomplish a task, and for me this is the one I was looking for.

  • Help with php session variables

    I am using Dreamweaver 8 to set up a dynamic app with PHP and
    MySQL. I want the code that the user logs in with ('UPN') to be
    stored as a session variable so that recordsets on subsequent pages
    can be set to display personalised data.
    I have set the session variable like this: $_SESSION['UPN'] =
    'UPN' (UPN is the name of the form textfield, also set as the
    username for logging in)
    On the data page, I have called the variable like this:
    $query_Recordset1 = ("SELECT pupils.pupilID, pupils.UPN,
    pupils.forename, pupils.surname FROM pupils WHERE UPN = '" .
    $_SESSION['UPN'] . "'");
    The recordset returns nothing- the dynamic table returns ony
    the column headings (both as headings and immediately under where
    you would expect the data to be).
    Can anyone help?
    Thanks

    On Wed, 17 Oct 2007 11:43:04 +0000 (UTC), "denman"
    <[email protected]> wrote:
    > I have set the session variable like this:
    $_SESSION['UPN'] = 'UPN' (UPN is
    >the name of the form textfield, also set as the username
    for logging in)
    Your code assigns the literal string UPN to the session
    variable. If
    it's coming from POSTed form data, you'd need to do it like:
    $_SESSION['UPN'] = $_POST['UPN'];
    Gary

  • Help with writing and retrieving data from a table field with type "LCHR"

    Hi Experts,
    I need help with writing and reading data from a database table field which has a type of "LCHR". I have given an example of the original code but don't know what to change it to in order to fix it and still read in the original data that's stored in the LCHR field.
    Basically we have two Function modules, one that saves list data to a database table and one that reads in this data. Both Function modules have an identicle table which has an array of fields from type INT4, CHAR, and type P. The INT4 field is the first one.
    Incidentally this worked in the 4.7 non-unicode system but is now dumping in the new ECC6 Unicode system.
    Thanks in advance,
    C
    SAVING THE LIST DATA TO DB
    DATA: L_WA(800).
    LOOP AT T_TAB into L_WA.
    ZDBTAB-DATALEN = STRLEN( L_WA ).
    MOVE: L_WA to ZDBTAB-RAWDATA.
    ZDBTAB-LINENUM = SY-TABIX.
    INSERT ZDBTAB.
    READING THE DATA FROM DB
    DATA: BEGIN OF T_DATA,
                 SEQNR type ZDBTAB-LINENUM,
                 DATA type ZDBTAB-RAWDATA,
               END OF T_TAB.
    Select the data.
    SELECT linenum rawdata from ZDBTAB into table T_DATA
         WHERE repid = w_repname
         AND rundate = w_rundate
         ORDER BY linenum.
    Populate calling Internal Table.
    LOOP AT T-DATA.
    APPEND T_DATA to T_TAB.
    ENDLOOP.

    Hi Anuj,
    The unicode flag is active.
    When I run our report and then to try and save the list data a dump is happening at the following point
    LOOP AT T_TAB into L_WA.
    As I say, T_TAB consists of different fields and field types whereas L_WA is CHAR 800. The dump mentions UC_OBJECTS_NOT_CONVERTIBLE
    When I try to load a saved list the dump is happening at the following point
    APPEND T_DATA-RAWDATA to T_TAB.
    T_DATA-RAWDATA is type LCHR and T_TAB consists of different fields and field types.
    In both examples the dumps mention UC_OBJECTS_NOT_CONVERTIBLE
    Regards
    C

  • Help with count and sum query

    Hi I am using oracle 10g. Trying to aggregate duplicate count records. I have so far:
    SELECT 'ST' LEDGER,
    CASE
    WHEN c.Category = 'E' THEN 'Headcount Exempt'
    ELSE 'Headcount Non-Exempt'
    END
    ACCOUNTS,
    CASE WHEN a.COMPANY = 'ZEE' THEN 'OH' ELSE 'NA' END MARKET,
    'MARCH_12' AS PERIOD,
    COUNT (a.empl_id) head_count
    FROM essbase.employee_pubinfo a
    LEFT OUTER JOIN MMS_DIST_COPY b
    ON a.cost_ctr = TRIM (b.bu)
    INNER JOIN MMS_GL_PAY_GROUPS c
    ON a.pay_group = c.group_code
    WHERE a.employee_status IN ('A', 'L', 'P', 'S')
    AND FISCAL_YEAR = '2012'
    AND FISCAL_MONTH = 'MARCH'
    GROUP BY a.company,
    b.district,
    a.cost_ctr,
    c.category,
    a.fiscal_month,
    a.fiscal_year;
    which gives me same rows with different head_counts. I am trying to combine the same rows as a total (one record). Do I use a subquery?

    Hi,
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    user610131 wrote:
    ... which gives me same rows with different head_counts.If they have different head_counts, then the rows are not the same.
    I am trying to combine the same rows as a total (one record). Do I use a subquery?Maybe. It's more likely that you need a different GROUP BY clause, since the GROUP BY clause determines how many rows of output there will be. I'll be able to say more after you post the sample data, results, and explanation.
    You may want both a sub-query and a different GROUP BY clause. For example:
    WITH    got_group_by_columns     AS
         SELECT  a.empl_id
         ,     CASE
                        WHEN  c.category = 'E'
                  THEN  'Headcount Exempt'
                        ELSE  'Headcount Non-Exempt'
                END          AS accounts
         ,       CASE
                        WHEN a.company = 'ZEE'
                        THEN 'OH'
                        ELSE 'NA'
                END          AS market
         FROM              essbase.employee_pubinfo a
         LEFT OUTER JOIN  mms_dist_copy             b  ON   a.cost_ctr     = TRIM (b.bu)
         INNER JOIN       mms_gl_pay_groups        c  ON   a.pay_group      = c.group_code
         WHERE     a.employee_status     IN ('A', 'L', 'P', 'S')
         AND        fiscal_year           = '2012'
         AND        fiscal_month          = 'MARCH'
    SELECT    'ST'               AS ledger
    ,       accounts
    ,       market
    ,       'MARCH_12'          AS period
    ,       COUNT (empl_id)       AS head_count
    FROM       got_group_by_columns
    GROUP BY  accounts
    ,            market
    ;But that's just a wild guess.
    You said you wanted "Help with count and sum". I see the COUNT, but what do you want with SUM? No doubt this will be clearer after you post the sample data and results.
    Edited by: Frank Kulash on Apr 4, 2012 5:31 PM

  • MOVED: [Athlon64] Need Help with X64 and Promise 20378

    This topic has been moved to Operating Systems.
    [Athlon64] Need Help with X64 and Promise 20378

    I'm moving this the the Administration Forum.  It seems more apporpiate there.

  • Need Urgent Help with Apache and PHP

    I have been struggling with apache and php for a week now and I finally broke down to post a message.
    I have apache 1.3 running on my mac mini g4 with 10.4.9 and I installed sql. I went to the entropy website and downloaded php5 to install without knowing I already had php4 on the machine. I installed 5 but could not get it to work. I then went back to httpd.conf and tried to install php4 by uncommenting out the loadmodule and addmodule lines. I restarted apache but php still did not work. I tested the phpinfo.php script but all I got was the script in Safari and not the actual page. At the moment, I have php4 and php5 on my machine but can't get either one to work. I am sure there is an easy fix but I don't know it. Please help.

    The problem is not terribly complicated, but Apache will not start with the entropy file in the folder
    /etc/httpd/users/
    Let me experiment on you. Rename the entropy file and then try to start Apache. To do this, open Terminal and paste this command:
    <pre>sudo mv /etc/httpd/users/+entropy.conf /etc/httpd/users/+entropy<pre>
    Now check the Apache configuration:
    <pre>apachectl configtest<pre>
    If it says "Syntax OK", start Apache:
    <pre>sudo apachectl start<pre>
    Since we only disabled the entropy file, you should be able to enable PHP5 with some more advanced configuring.

  • Need help with FlashVars and PHP

    I'm trying to pass a variable (an mp3 URL) generated from a SQL query with PHP to a small flash mp3 player embedded in the page. I am using FlashVars and its not receiving the .swf is not receiving the variable.
    Here is the embed code:
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,79,0" width="35" height="35">
    <param name="movie" value="http://www.myurl.com/audioButton.swf"  />
    <param name="quality" value="high" />
    <param name="FlashVars" value="theFile=<?php echo $myaudio; ?>" />
    <embed src="example.swf" width="550" height="400" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" flashvars="theFile=<?php echo $myaudio; ?>"></embed>
    </object>
    I've declared the variable at the top of the page like so:
    $myaudio = "http://www.myurl.com/demo.mp3";
    When I load the page, the flash player doesn't play the mp3. But if I put the mp3 URL directly into the embed code (see below) it works ...
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,79,0" width="35" height="35">
    <param name="movie" value="http://www.r2creative.com/audioButton.swf"  />
    <param name="quality" value="high" />
    <param name="FlashVars" value="theFile=http://www.myurl.com/demo.mp3" />
    <embed src="example.swf" width="550" height="400" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" flashvars="theFile=http://www.myurl.com/demo.mp3"></embed>
    </object>

    Ok. I see where my problem is. What I'm ultimately trying to do is query a database of podcasts, and when they are displayed on a php page, have a small flash button next to each which streams the audio.
    I was placing the entire embed code of the flash player and placing into a field in the database (audioPlayer) and using another field (mp3Link) a the source. The page was displaying the players next to the podcasts but there was no audio.
    I just placed the embed code directly into the page and it works, so the flashvars problem is solved - outputting the embed code from the database must not work for some reason. I'm still not sure how I'll accomplish this, but I know now that the swf was receiving the variable.
    Thanks guys.

Maybe you are looking for

  • Using Cinema Display

    Kind and Intelligent People, I have a MacBook that I use with a 23" Cinema Display when I am in my office. I want the Cinema Display to function as my 'desktop', and the MacBook display can be black for all I care. I do not want to 'mirror' the displ

  • Income payment order - UK payroll

    Hi all, I need a confirmaiton on whether SAP supports for Income payment orders in UK payroll like court orders? If yes can you please provide me the details please. Thanks All in advance, Veena

  • V$timer problem

    Hi, I want to know something moer about v$timer v$timer:This view lists the elapsed time in hundredths of seconds.. So does it mean SQL> select * from v$timer;      HSECS 4017590975My Db was running from last 464 days i.e 4017590975/100=x sec x/60 =y

  • Web.xml + jsp-config element missing in definition?

    Hi, I have problem with jsp-config element definition in web.xml - I checked web-app_2_5.xsd it's reffering to javaee_5.xsd - but it's missing there from web xsd: <xsd:element name="jsp-config"           type="javaee:jsp-configType"/> There is no jav

  • Quiz Retake - Adobe Presenter 9

    Hi, Does Adobe Presenter 9 have the ability to allow the user to only retake the questions they got wrong on a quiz instead of repeating the entire quiz? I know AP8 doesn't and I looked on all the Adobe information I could find on AP9 and didn't see