AyKay47
Members-
Posts
3,281 -
Joined
-
Last visited
-
Days Won
1
Everything posted by AyKay47
-
matches for me when tested.. $str = '<td>Тип</td><td valign="top" align=left>Филми</td></tr>'; $pattern = '~Тип</td><td(?>[^>]+)>((?>[^<]+))</td>~'; preg_match($pattern,$str,$ms); print_r($ms); results: Array ( [0] => Тип</td><td valign='top' align=left>Филми</td> [1] => Филми )
-
ah, $str = "Category</td><td valign='top' align=left>MOVIES</td>"; $pattern = "~Category</td><td(?>[^>]+)>((?>[^<]+))</td>~"; preg_match($pattern,$str,$ms); print_r($ms); $ms[1] will hold the captured value, in this case "MOVIES"
-
Filter number from string, except when between curly braces
AyKay47 replied to pr0no's topic in Regex Help
{:70{}} Repeating the OP for clarity: "I need to adjust the regex to completely ignore whatever there is between curly braces". i had thought of that, but im not going to assume that there can be nested curly braces, since I am assuming that this is a pre-formatted string. That is what he is getting until I am notified otherwise by the OP... -
Filter number from string, except when between curly braces
AyKay47 replied to pr0no's topic in Regex Help
I disagree -
I wrote the rewrite backwards, change to: RewriteEngine On RewriteRule ^/09search_results.php?search_KEYWORD=([a-z]+)&search_RANGE=([a-z]+)&o=([0-9]+)&search=[0-9]+$ /$2/$1/$3 [NC, L]
-
category in you pattern will never match type in the string. do you want to match anything in between table columns? if so... $str = "Type</td><td valign='top' align=left>MOVIES</td>"; $pattern = "~<td(?>[^>]+)>((?>[^<]+))</td>~"; preg_match($pattern,$str,$ms); print_r($ms); if not, specify the requirements more thoroughly.
-
man you guys are so picky/lazy...
-
Filter number from string, except when between curly braces
AyKay47 replied to pr0no's topic in Regex Help
thanks salathe, I was in a hurry to get out the door before I put this together so I did not have time to thoroughly test it, I appreciate you pointing out the hole in the pattern. I have revised the pattern and also made it a bit simpler, but more powerful. $pattern = "~([\d.]+)(?![^{]*})~"; this will match any digit along with a decimal as long as it finds an opening bracket before it finds a closing bracket. -
My solution has no backtracking in it... ummm.... yeah I just looked it over again and it shouldn't backtrack on a match you're right. wait... you edited the function and didn't call it in your code at all.. since you clearly do not understand how it should be implemented, i will hold you hand: <script> function validateStr(arr) //don't touch this function { for(index=0;index<arr.length;index++) { if(/^[a-z]+$/i.test(arr[index]) === false) { return false; } } } var str = document.searchform.searchField.value; //validate that this is in the correct format to be split var arr = str.split(" , "); //delimiter can be changed if desired if(validateStr(arr) === false) alert("failed"); else alert("passed"); </script>
-
Filter number from string, except when between curly braces
AyKay47 replied to pr0no's topic in Regex Help
okay I have cooked something up for you: echo preg_replace("~(?<![a-z{:])([0-9.]++)(?![a-z}])~i","{NUMBER: $1}","Dat foo 13.45 and $600 bar {baz:70} and {8}"); output: Dat foo {NUMBER: 13.45} and ${NUMBER: 600} bar {baz:70} and {8} I optimized your code a little and tweaked it a bit based on the specifications in your post. I believe the main issue with your pattern is that the negative lookbehind would allow any other character other than an opening curly brace "{" to preced it. so things like {teststring90test} would pass. Since you had the negative lookahead disallowing the number to be follwed by a closing curly brace, the regex had no choice but to only match the 7 in {baz:70} since it could not match the 70 which it wanted to. -
ok so i did it like this one $percentage = round(($students_detention_num / $total_students) * 100); but the number gives me this? Percentage 400% 270 total detentions 1080 total students 400 2701080 well, lets break it down (like MC hammer),if you did it correctly it would look like this. $percentage = round((270 / 1080) * 100); //down a step $percentage = round(.25 * 100); //down another step $percentage = round(25); $percentage = 25%; it seems that you have switched the parameters.
-
true, i use functions where I can for re-usability in my code, as i believe it should be.
-
for reason this accepts all now what? anyway, here is something i put together, since i am not a fan of using regex's that have to backtrack if it can be avoided (and im bored). <script type="text/javascript"> function validateStr(arr) { for(index=0;index<arr.length;index++) { if(/^[a-z]+$/i.test(arr[index]) === false) { return false; } } } var str="test , test , test"; var arr = str.split(" , "); if(validateStr(arr) === false) { alert("failed"); } else { alert("pass"); } </script> this splits the string by the delimiter space comma space, which will isolate each case, then checks against the regex, returning false if it fails.
-
so you would find the total number of students, total number of students that have detention or whatever, then plug them into the function. $percentage = returnPercent($students_detention_num,$total_students)
-
err.. function should look like this. function returnPercent($num,$total) { return round($num / $total * 100) . "%"; } So the $num1 = the first filed in table? $num = field 2 i don't follow... the above function will find the percentage of two numbers divided together. If this is not what you want, give an example of exactly what you want.
-
Yes, CV's script will work for what you need. Never pollute the database.
-
i must ask first, why are you using javascript to validate anything
-
the success of the query should not affect any code below it, unless it is written incorrectly. Perhaps make a new thread with this new issue, or post it on here if you want us to take a look.
-
causing the regex engine to find a match a little quicker, nice thanks. My thought is that it is more simple and easier to code and read than having to fuck with keeping track of row lengths and file positions. I agree, not to mention that we do not know the skill level of the OP, or if he/she would understand messing with line lengths and file pointer positions etc (no offense OP).. I'm not a fan of giving code that the user will not understand. But thanks for the pointers, I appreciate it.
-
Remove the comma before the "FROM". I also prefer to format my queries in multiple lines to make them easier to read/analyze. $query = "SELECT Car_Make, Car_Model, Image_Van FROM products WHERE Car_Make= '$strMake' AND Car_Model = '$strModel'"; missed that, thanks
-
okay here's what I've come up with for you. Since you haven't given me a lot to work with as far as what values can possibly in the values spots of the querystring, i will go off of specifically what you gave me. RewriteEngine On RewriteRule ^/([a-z]+)/([a-z]+)/([0-9]+)$ /09search_results.php?search_KEYWORD=$1&search_RANGE=$2&o=$3 [NC, L]
-
you're concatenating incorrectly, and it's not even needed. this will do fine: $query = "SELECT Car_Make, Car_Model, Image_Van, FROM products WHERE Car_Make= '$strMake' AND Car_Model = '$strModel'";
-
I appreciate the thought out response, and I agree with you fully. I completely overlooked the fact that this file is 150k lines plus. Using a regex in that situation would simply be retarded, as it would more than likely roll over the server. Thanks for catching my horrible mistake here, I would have never suggested this if I would have read the OP thoroughly. The snippet of code you provided is very efficient and readable, i like it. I do question creating a new destination file, but we do not know enough of the OP's situation to justify either way. Thanks also for pointing out the back reference error I made, that was simply an error on my part.
-
I wrote one sentence.... ok, these lines that you have here: $query = "SELECT Car_Make, Car_Model, Image_Van FROM products WHERE Car_Make='$make' AND Car_Model='$model'"; // the result of the query $result = mysql_query($sql) or die("Invalid query: " .mysql_error()); you have $query set to the SQL statement (your select statement). Now when you use mysql_query() below that, you use the variable $sql, $sql does not hold the SQL statement, $query does. So $query needs to be used as the mysql_query() parameter. The code that I provided in my last reply has the updated code.
-
in the above code, $query holds the SQL, in your mysql_query call you are using $sql, which holds nothing. $query = "SELECT Car_Make, Car_Model, Image_Van FROM products WHERE Car_Make='$make' AND Car_Model='$model'"; // the result of the query $result = mysql_query($query) or die("Invalid query: " .mysql_error());