Jump to content

Jason28

Members
  • Posts

    132
  • Joined

  • Last visited

Everything posted by Jason28

  1. I tried different only tools and tutorials about mod_rewrite but I cannot find what I am looking for. I want to rewrite a url like this (I wont include site domain since it is all within the same site directory): /area-1/(random text here)/category-5/(random text here)/ I only want it to find the area number within the slashes /area-ID/ and the category within the slashes /category-ID/ and ignore all of the other text since it changes based on the page title. I tried: RewriteRule ^area-([-0-9]+)/([^/]*)/category-([-0-9]+)\/ test.php?id=$1&var=$2&cat_id=$3 [L] The $var=2 is empty and not needed, but needed to add something there to ignore the stuff in the middle. Please help, I cannot create an account at Stackoverflow because the signup always errors. I contacted their webmaster with no reply. Thanks.
  2. Ha I figured it out myself using W3schools and only one line of code thanks for nothing screw Jquery.
  3. Hmm I doubt I need jquery for that since I have seen javascript do that years before jquery or ajax was even invented. This is not a help site? It has been helping people for years. I cannot find my answer on stackoverflow, I have been searching for hours. I work 14 hours per day at my full time job and code after that so I am far from lazy.
  4. I have spent so many years trying to figure out javascript and just cannot learn it. Especially when all of the code is correct but it doesn't work. Anyway, I need a very simple javascript code that everyone here should know please... I want to pass two values via a url, to another spot on the same webpage. So like a url with javascript function (50,60) will change the values of the an iframe on that page from <iframe style="height: 50px, width:60px">. So I will pass the height and width values to the iframe on the page when I click on a url. Please provide full code thanks
  5. Ah nevermind again I found it here this works: http://www.ozzu.com/programming-forum/ignoring-iframes-with-javascript-history-t67189.html
  6. I searched all over the internet and everyone has similar questions but not what I am looking for. Those who did get a solution only received part of the code as they assumed the person was an expert in javascript. I suck at javascript so I couldn't make it work. I have links on a webpage and when you click on the links it displays the page in an iframe. When you use the browser's back window it causes the info in the iframe to go back instead of the main page. How do I make it so that the main page goes back and not the iframe? I tried using header codes to not cache the iframe page but it doesnt work. OH and please no heavy Jquery, I imagine something simple can prevent this. Thanks.
  7. Hello, I cannot figure this out... I will leave out most of the code to not confuse you, but I have it almost working so I am just missing something. I have two arrays, one that contains the IDS that I want correctly. Here is the first array when I print it out: Array ( [0] => 3 [1] => 9 [2] => 11 ) Perfect, it displays the IDS 3, 9, and 11 like it should. Now here is my second array when printed out: Array ( [0] => name value [1] => maker value [2] => year value ) That works too. name value, maker value, and year value are the results. I tried using an array_merge on those two arrays hoping that it will turn it into 3 => 'name value', 9 => 'maker value', 11 => 'year value' For some reason the result I get when I merge these two arrays is: Array ( [0] => 3 [1] => 9 [2] => 11 [3] => name value [4] => maker value [5] => year value ) It does merge them, but as separate array values. So when I use my foreach() to insert the values into a DB, I get this as a result: INSERT INTO fields_table (field_id, field_value) VALUES ('0', '3') INSERT INTO fields_table (field_id, field_value) VALUES ('1', '9') INSERT INTO fields_table (field_id, field_value) VALUES ('2', '11') INSERT INTO fields_table (field_id, field_value) VALUES ('3', 'name value') INSERT INTO fields_table (field_id, field_value) VALUES ('4', 'maker value') INSERT INTO fields_table (field_id, field_value) VALUES ('5', 'year value') What do I do to make the first values equal the second values please? Thanks. EDIT HAHA I finally figured this out when creating this topic! I have to use array_combine() instead of array_merge it works perfect now Nevermind I solved it!
  8. Oh ok. Personally I do not mind that the comments do not work though. Well thanks a lot for all of the work you have put in this, that is the most free help I have ever received
  9. Hello, I wasn't sure if you meant replace all of the ^ or just the first one, so I tried both: '/(^|\)\s*)\s*\{(([(^|\)\s*)"\'{}]*|"([(^|\)\s*)\\\\"]+|\\\\.)*"|\'([(^|\)\s*)\\\\\']+|\\\\.)*\'|(?R))*)\}/m' No indention, and the second time I only replaced the first ^ '/(^|\)\s*)\s*\{(([^"\'{}]*|"([^\\\\"]+|\\\\.)*"|\'([^\\\\\']+|\\\\.)*\'|(?R))*)\}/m' It had a blank output. Would it be easier if I pm'ed you the whole code and the file I am trying to edit or would you rather we continue posting in this topic? Thanks
  10. Hello requinix, wow, that is some complex stuff It worked when I entered the function as a test in the field and made it work. However I tried pasting a whole file's worth of code like I did before and it resulted in a blank result. Your regex worked fine before, is it possible it can just be slightly edited to only work after detecting an end parenthesis ) or perhaps only outside of quotation marks or some other workaround? Thanks so much
  11. I tried adding a [^\)]* in there to only work after the end parenthesis and either I put it in the wrong spot or it is the wrong code since it didn't work
  12. Yes I understand that thanks. I am using this function to clean up code of old scripts that do use brackets within quotes. I just need the function requinix created to only tab when the bracket comes after an end parenthesis and then it will be complete.
  13. Sorry, I had to make another post as I can no longer edit the one above. I promise this will be the last time I bother you Yes I see it tabbed after the first bracket in the function which is why it broke. Can you make it only tab if the first curly bracket has an end parenthesis before it? Also, it seems to tab even if there is already a tab within the parenthesis. Thank you so much for your time
  14. There is something weird though. I entered your function into the post and it indented it, but for some reason it breaks its function and doesn't work when indented: function indent($code) { // first find all the sets of code blocks $formatted = preg_replace_callback('/\{ (([^{}]*|(?R))*)\}/', function($matches) { // now we're replacing them // $matches[0] is the entire code block unformatted // $matches[1] is just the code inside $innercode = $matches[1]; // apply indentation $innercode = preg_replace('/^[ \t]*\S/m', "\t\$0", $innercode); // then apply indentation to any code blocks inside this one $innercode = indent($innercode); // return. don't forget to add the {}s back return "{" . $innercode . "}"; }, $code); return $formatted; } I also just noticed a problem that I am not sure can be resolved. Some variables that are between quotations like echo "Hello {$username}"; are converted into: echo "Hello { $username}"; If I had to guess on how to fix it, I would make it only indent after it detects an end paranthesis before the first curly bracket? Like if () { } it will see the ) { or ) (next empty line) { as the trigger?
  15. requinix are you extremely impressive wow, thanks so much it works People say that I know my stuff but I cannot touch you.
  16. Ok, interesting Hostgator told me to add a couple of lines of code to my htaccess to activate version 5.3.6 and that is the version it is using now. The error went away, but I am dead tired as I haven't been to sleep yet so I will test it out when I wake up. I do notice that you use: $code = <<<PHP if (\$condition) { if (\$other_condition) { do_something(); } else { do_something_else(); } } PHP; I am going to be posting text from a form and it is not PHP only but other languages and text as well. So would: $code = $_POST['code'] work with this function? Thanks a lot!
  17. Yeah I use hostgator and it looks like I am using PHP 5.2.17 and I get the error: with this line: $formatted = preg_replace_callback('/\{(([^{}]*|(?R))*)\}/', function($matches) { It also looks like it will error on this part too: }, $code);
  18. Yay! Thanks so much requinix I will test it out shortly
  19. Thank you so much for your reply. Please do not get mad at me, but you are way smarter than me and I have no idea how to write out what you just said. Do you want me to do this? function blah($var) { $var = preg_replace_callback('/\{(([^{}]*|(?R))*)\}/', "$1", $var); $var = preg_replace_callback('/^\s*\S/m => \t$0', "$1", $var); return $var; } Sorry I do not speak the regex lingo and I tried reading tutorials but all they do is give me a migraine and when I think I understand it and put it to the test they do not work. It would be great if you could show me the code to use please that would really make my week. BTW all of this code appears in a text format as I am submitting it using a $_POST form and going to copy the result and paste it into my php files.
  20. I have spent hours trying to figure this out so I really hope you can make it work. I would imagine it is not that hard? I would like PHP to detect everything, spaces, tabs, letters, numbers, symbols, everything within brackets and tab them. So that an example: if($surl1 == "") { // blah blah $surl1 = "http://"; } while($row=mysql_fetch_array($result) { echo $row['name']; } would be converted into: if($surl1 == "") { // blah blah $surl1 = "http://"; } while($row=mysql_fetch_array($result) { echo $row['name']; } Please this has to be possible? I am really stressing and trying to make it work but I suck at Regex. Someone said use this: $string = preg_replace('#\{.*?\}#s', "/t", $string); but it doesn't work for me and it doesn't look correct, especially with just the \t there shouldn't there be a $1 or something in there too? Maybe it does work with further tweaking?
  21. Excellent, works perfectly I had no idea just adding basename() would be the solution.
  22. But doesn't that add multiple files into one zip?
  23. Thanks but what part of that code do I replace with the one you provided?
  24. Thanks for the quick reply. I realized this problem doesn't happen if the file is located in the www or public_html directory, only when the directory is in a non accessible from the web directory. The following code is the original that works when the file is in the public folder. If you create a directory before the public folder and use the path to it, you will see that it creates multiple folders: <?php /* creates a compressed zip file */ function create_zip($files = array(),$destination = '',$overwrite = false) { //if the zip file already exists and overwrite is false, return false if(file_exists($destination) && !$overwrite) { return false; } //vars $valid_files = array(); //if files were passed in... if(is_array($files)) { //cycle through each file foreach($files as $file) { //make sure the file exists if(file_exists($file)) { $valid_files[] = $file; } } } //if we have good files... if(count($valid_files)) { //create the archive $zip = new ZipArchive(); if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) { return false; } //add the files foreach($valid_files as $file) { $zip->addFile($file,$file); } //debug //echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status; //close the zip -- done! $zip->close(); //check to make sure the file exists return file_exists($destination); } else { return false; } } // sample: $files_to_zip = array( 'test.txt', 'index.html' ); $full_zip_path = '/home/bob/public_html/test/'; // trailing slash $zipped_name = 'my-test.zip'; $final_destination = $full_zip_path . $zipped_name; //if true, good; if false, zip creation failed $result = create_zip($files_to_zip, $final_destination); if ( !$result ) { echo 'error'; } else { echo 'zip was successful'; } ?>
×
×
  • 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.