Results 1 to 4 of 4

Thread: PHP RegEx Incorrect

  1. #1
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default PHP RegEx Incorrect

    1) Describe Work Request (be as detailed as possible): I can't quite get this to work quite right I know I'm writing a new line or tab incorrectly.

    I'm using 3 txt files and 3 php files...

    2bedone.txt:

    Code:
    <table border="1">
    	<tr>
    		<td style="font-weight:bold;">Pending Task</td>
    		<td style="font-weight:bold;">Date Requested</td>
    		<td style="font-weight:bold;" id="user">Requestor</td>
    	</tr>
    </table>
    done.txt:

    Code:
    <table border="1">
    	<tr>
    		<td style="font-weight:bold;">Task Completed</td>
    		<td style="font-weight:bold;">Date Requested</td>
    		<td style="font-weight:bold;">Date Completed</td>
    	</tr>
    </table>
    r_count.txt:

    Code:
    0

    performed.php:

    PHP Code:
    <?php
    if (isset($_GET['id_is'])) {
        
    $id_on $_GET['id_is'];
        
    $pending_file '2bedone.txt';
        
    $pending_files file_get_contents($pending_file);
        
    $pattern '/<tr id="' $id_on '">\n\t\t<td>(.*)<\/td>\n\t\t<td>(.*)<\/td>\n\t\t<td class="user">(.*)<\/td>\n\t<\/tr>\n/';
        
    $replacement "";
        
    preg_match($pattern$pending_files$matches);
        echo 
    "\nMatches\n" $matches[0];
        
    $move_over preg_replace($pattern$replacement$pending_files);
        echo 
    "\nMove Over\n" $move_over;
        
    file_put_contents($pending_file$move_over);
        
    //Write to done file
        
    $hour date("g") + 1;
        
    $date date("n/d/y $hour:i:s a");
        
    $complete_file 'done.txt';
        
    $complete_files file_get_contents($complete_file);
        
    $second_pattern '/<\/td>\n\t<\/tr>\n<\/table>/';
        
    $second_replacement "</td>\n\t</tr>\n$matches[0]</table>";
        echo 
    "\n2nd Pattern\n" $second_replacement;
        
    $holder preg_replace($second_pattern$second_replacement$complete_files);
        
    $third_pattern '/<tr id="' $id_on .'">\n\t\t<td>(.*)<\/td>\n\t\t<td>(.*)<\/td>\n\t\t<td class="user">\d+<\/td>\n\t<\/tr>/';
        
    $third_replacement "<tr id=\"$id_on\">\n\t\t<td>$1</td>\n\t\t<td>$2</td>\n\t\t<td>$date</td>\n\t</tr>";
        
    $completed_content preg_replace($third_pattern$third_replacement$holder);
        
    file_put_contents($complete_file$completed_content);
    //    header("Location: http://NotLive.net/taskmanager/index.php?submit_change=2");
    } else {
        
    header("HTTP/1.0 404 Not Found");
    }
    ?>
    index.php:

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <title>Changes Tasks</title>
        </head>
        <body>
    <?php
    if (isset($_GET['submit_change']) && $_GET['submit_change'] == "1") {
    ?>
        <form action="process.php" method="post">
            Task:<br /><textarea name="pending"></textarea><br />
            Requestor:<select name="requestor">
                        <option value="0">User/IT</option>
                        <option value="1">Video Request</option>
            </select><br />
                 <input type="submit" value="Submit" />
        </form>
         </body>
    </html>
    <?php
    }
    if (!isset(
    $_GET['submit_change']) || $_GET['submit_change'] !=2) {
    ?>
            <h1>Pending Tasks</h1>
            <?php
            $pending_tasks 
    file_get_contents('2bedone.txt');
            
    $pending_tasks str_replace('class="user">0</td>'"class=\"user\">User Request</td>"$pending_tasks);
            
    $pending_tasks str_replace('class="user">1</td>'"class=\"user\">Video Request</td>"$pending_tasks);
            echo 
    $pending_tasks "\n";
            
    ?>
            <h1>Completed Tasks</h1>
            <?php
            $complete_tasks 
    file_get_contents('done.txt');
            echo 
    $complete_tasks "\n";
            }
    if (isset(
    $_GET['submit_change']) && $_GET['submit_change'] == "2") {
    if (!isset(
    $_POST['p_word'])) {
    ?>
    <form action="?submit_change=2" method="post">
        <input name="p_word" type="password" />
         <input type="submit" value="Submit" />
    </form>
    <?php
    }
    if (isset(
    $_POST['p_word']) && $_POST['p_word'] == "password" ) {
        
    $pending_tasks file_get_contents('2bedone.txt');
        
    $pattern '/<tr id="(\d+)">\n\t\t<td>(.*)<\/td>\n\t\t<td>(.*)<\/td>\n\t\t<td class="user">(.*)<\/td>\n\t<\/tr>/';
        
    $replacement "<tr id=\"$1\">\n\t\t<td><a href=\"http://NotLive.net/taskmanager/performed.php?id_is=$1\">$2</a></td>\n\t\t<td><a href=\"http://NotLive.net/taskmanager/performed.php?id_is=$1\">$3</a></td>\n\t\t<td class=\"user\"><a href=\"http://NotLive.net/taskmanager/performed.php?id_is=$1\">$4</a></td>\n\t</tr>";
        
    $list_changes preg_replace($pattern$replacement$pending_tasks);
        echo 
    $list_changes;
    }
    ?>
         </body>
    </html>
    <?php
    }
    ?>
    From index.php there are 3 pages...

    1. index.php?submit_changes=1 this loads a form to submit a new request
    2. index.php?submit_changes=2 this loads a securish form that once verified the user can send a task from the 2bedone to the done.txt
    3. index.php this shows all tasks pending and all tasks done.

    Please let me know if there are any other questions. This works for adding a task and swapping just not together, the txt files must be altered for that.

    2) Payment methods you support (ie: Paypal, 2checkout etc):

    Paypal

    Not sure how much time this will take someone, I'd imagine not much for someone with a good understanding though...
    Last edited by bluewalrus; 06-22-2010 at 01:49 PM.
    Corrections to my coding/thoughts welcome.

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,067
    Thanks
    95
    Thanked 98 Times in 96 Posts

    Default

    Hi, hope you don't mind me poking my nose in here, but your problem sounds interesting.

    I was looking over your post and the codes. Could you post the code for process.php?
    To choose the lesser of two evils is still to choose evil. My personal site

  3. #3
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    I actually just found the problem, it was pretty simple I just needed to start the searches with a tab as well because I wasn't replacing it otherwise.

    I.E the patterns should be

    PHP Code:
    $pattern '/\t<tr id="' $id_on '">\n\t\t<td>(.*)<\/td>\n\t\t<td>(.*)<\/td>\n\t\t<td class="user">(.*)<\/td>\n\t<\/tr>\n/'
    instead of

    PHP Code:
    $pattern '/<tr id="' $id_on '">\n\t\t<td>(.*)<\/td>\n\t\t<td>(.*)<\/td>\n\t\t<td class="user">(.*)<\/td>\n\t<\/tr>\n/'
    Corrections to my coding/thoughts welcome.

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    So, out of curiosity, how much are you going to pay yourself for the solution?

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
  •