Search the Community
Showing results for tags 'php fopen'.
-
Hi all. I have a php file that i need to read contents from. I can search for a string but i am stumped on how to start from a point and to end at a point Below is the payout of the file. I just want to return Paul1 plist1: plist1 plist2: plist2 plist3: plist3 plist4: plist4 and not the rest. quote_lost_reason "": "" Price: Price Product: Product Other: Other Paul1 plist1: plist1 plist2: plist2 plist3: plist3 plist4: plist4 Site Lighting Interior: Interior Exterior: Exterior credit credit_note: Credit Note here is my code so far $file = '/var/www/html/***/custom/include/language/lang.en_us.lists.php'; $searchfor = "Paul1"; $array = file($file); //print_r($array); header('Content-Type: text/plain'); $contents = file_get_contents($file); $pattern = preg_quote($searchfor, '/'); $pattern = "/^.*$pattern.*\$/m"; if(preg_match_all($pattern, $contents, $matches)){ echo "Found matches:\n"; echo implode("\n", $matches[0]); } else{ echo "No matches found"; }
-
$("input.class_input_button_send").on("click",function(event) { event.preventDefault(); //var username = $("input.class_input_hidden").val(); var typed_text = $("input#id_input_text_type").val(); console.log(typed_text); rt = $.ajax({ type: "POST", url: "send.php", data: { name: "", typed_text: typed_text }, success: function(data) { console.log(data); console.log(data.length); } }).done(function() { alert( "success" ); }) .fail(function() { alert( "error" ); }); //console.log(rt); }); send.php =><?php <?php if( session_id() == '' ) { session_start(); } if($_SERVER['SERVER_PROTOCOL'] == "HTTP/1.1") { $domain_host_root = "http://" . $_SERVER['SERVER_NAME'] . "/"; } require_once 'core/model/mysql/mysqldb.php'; require_once 'core/utility/debug-app.php'; require_once 'core/utility/utility.php'; require_once 'core/view/view.php'; //$_POST['typed_text'] = "abc"; $typed_text = $_POST['typed_text']; $objDateTime = new DateTime('NOW'); $target_file = $objDateTime->format("Y-m-d"); $handle = fopen("archive/" . $target_file . ".txt", "w+"); fwrite($handle, $target_file_data); echo json_encode($target_file); ?> fopen function is working inside that send.php script if i run this as a standalone script, but fopen function returns null through the jquery $.ajax() function.