Jump to content

HuggieBear

Members
  • Posts

    1,899
  • Joined

  • Last visited

Posts posted by HuggieBear

  1. I expect this line

    $module = ("INSERT INTO test (`Tes_Name`, `Tes_Description`, `Use_ID`, `Sub_ID`) VALUES ($Tes_Name, $Tes_Description, $Use_ID, $Sub_ID)")

    is meant to be

    $module = mysql_query("INSERT INTO test (`Tes_Name`, `Tes_Description`, `Use_ID`, `Sub_ID`) VALUES ($Tes_Name, $Tes_Description, $Use_ID, $Sub_ID)")

  2. Why when this is running as a cron job are you outputting all that HTML?  Also, some of those errors are relating to the file handle, so when you're debugging, it might be handy to NOT suppress the errors.

     

    Change this

    $fp=@fopen("active_members/".$file, 'w');

    To this

    $fp=fopen("active_members/".$file, 'w');

  3. Try parentheses around the date range

    $query = "SELECT * FROM table WHERE hdt1 like '%$hdt1_search%' and hdt2 like '%$hdt2_search%' and hdt3 like '%$hdt3_search%' and dateadd like '$dateadd_search' and  (dateadd >= '$start_date' AND dateadd <= '$end_date') ";

  4. Try this, I've simplified the regular expression for the purposes of the example, and I only tested it with a static array, now I've added your DB code back in, I may have made a mistake.

    // Get words from the database and stick them into arrays
    $words = mysql_query("SELECT * FROM badwords WHERE 1");
    
    while($row = mysql_fetch_array($words)){
        $badwords[] = "/" . $row['word'] . "/i";
        $goodwords[] = $row['rword'];
    }
    
    $ad_title2 = $ad_title;
    $ad_body2  = $ad_body;
    
    // Replace the bad words with the good words
    $ad_title2 = preg_replace($badwords, $goodwords, $ad_title2, -1, $title_rep);
    $ad_body2 = preg_replace($badwords, $goodwords, $ad_body2, -1, $body_rep);
    
    // Echo the replacement count and the new title and body 
    echo "Title replacements: " . $title_rep . "<br />\n";
    echo "Body replacements: " . $body_rep . "<br />\n";
    echo "$ad_title2<br />\n";
    echo "$ad_body2<br />\n";

  5. In PHP you could try checking $_SERVER["HTTP_USER_AGENT"] for the string, as mine shows up as this

    Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.107 Safari/534.13
  6. Change these lines

    $ad_title2 = preg_replace("/([^a-z^A-Z]?)($match)([^a-z^A-Z]?)/i", "$1".$replacement."$3", $ad_title2);
    $ad_body2 = preg_replace("/([^a-z^A-Z]?)($match)([^a-z^A-Z]?)/i", "$1".$replacement."$3", $ad_body2);

    to these:

    $ad_title2 = preg_replace("/([^a-z^A-Z]?)($match)([^a-z^A-Z]?)/i", "$1".$replacement."$3", $ad_title2, -1, $title_rep);
    $ad_body2 = preg_replace("/([^a-z^A-Z]?)($match)([^a-z^A-Z]?)/i", "$1".$replacement."$3", $ad_body2, -1, $body_rep);

    Then $title_rep contains the replacement count from the title and $body_rep contains the body replacement count.  Check out the docs for preq_replace()

  7. You need to perform a comparison in your own function.  Here's my code that sorts by price ascending.

    <?php
    // Setup product array (You already have yours)
    $products = array(
                    'Bike' => array('price' => '199.99'),
                    'Apple' => array('price' => '0.87'),
                    'Car' => array('price' => '5999.00')
                );
    
    // Comparison function (swap the 1 and -1 around to sort descending)            
    function compare($x, $y){
        if ( $x['price'] == $y['price'] ){
            return 0;
        }
        else if ( $x['price'] < $y['price'] ){
            return -1;
        }
        else {
            return 1;
        }
    }
    
    // Sort the products
    uasort($products, 'compare');
    
    // Output the products
    echo '<pre>';
    print_r($products);
    echo '</pre>';
    
    ?>

  8. If you're viewing and running on Windoze then you might want to try this, it should add the End Of Line character for that specific OS.  On Windoze I believe it's "\r\n"

     

    <?php
    
    // Declare Array
    $tmp = array();
    
    // Hard coded details for testing
    $AccountNumber = "00040";
    $AccountName = "Microsoft";
    
    // Add Account Number
    if ($AccountNumber == "00040") {
       $tmp[] = "<ACCOUNT_NO>";
       $tmp[] = "Account Number is 00040";
       $tmp[] = "</ACCOUNT_NO>";
    }
    else {
       $tmp[] = "<ACCOUNT_NO>";
       $tmp[] = "Account Number is not 00040";
       $tmp[] = "</ACCOUNT_NO>";
    }
    
    // Attempt to add a new line to separate sections as implode wont add additional line
    $tmp[] = PHP_EOL;
    
    // Add Account Name
    if ($AccountName == "Microsoft") {
       $tmp[] = "<ACCOUNT_NAME>";
       $tmp[] = "Account Name is Microsoft";
       $tmp[] = "</ACCOUNT_NAME>";
    }
    else {
       $tmp[] = "<ACCOUNT_NAME>";
       $tmp[] = "Account Name is not Microsoft";
       $tmp[] = "</ACCOUNT_NAME>";
    }
    
    // Write contents to a file
    file_put_contents('accounts.txt',implode(PHP_EOL, $tmp));
    
    ?>

  9. OK, I've tried this and it appears to be working:

    <?php
    
    // Declare Array
    $tmp = array();
    
    // Hard coded details for testing
    $AccountNumber = "00040";
    $AccountName = "Microsoft";
    
    // Add Account Number
    if ($AccountNumber == "00040") {
       $tmp[] = "<ACCOUNT_NO>";
       $tmp[] = "Account Number is 00040";
       $tmp[] = "</ACCOUNT_NO>";
    }
    else {
       $tmp[] = "<ACCOUNT_NO>";
       $tmp[] = "Account Number is not 00040";
       $tmp[] = "</ACCOUNT_NO>";
    }
    
    // Attempt to add a new line to separate sections as implode wont add additional line
    $tmp[] = "\n";
    
    // Add Account Name
    if ($AccountName == "Microsoft") {
       $tmp[] = "<ACCOUNT_NAME>";
       $tmp[] = "Account Name is Microsoft";
       $tmp[] = "</ACCOUNT_NAME>";
    }
    else {
       $tmp[] = "<ACCOUNT_NAME>";
       $tmp[] = "Account Name is not Microsoft";
       $tmp[] = "</ACCOUNT_NAME>";
    }
    
    // Write contents to a file
    file_put_contents('accounts.txt',implode("\n",$tmp));
    
    ?>

     

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.