-
Posts
15,229 -
Joined
-
Last visited
-
Days Won
427
Everything posted by requinix
-
I'm not that familiar with CI: is application/ an actual directory or just a part of the URL?
-
If all you want is to learn what it does then it's easier to just learn (to read) ASP than to try to transcode everything into PHP. Classic ASP is written in Visual Basic: practically the easiest language to read ever invented. I mean heck, just look at it and take a guess based on the names of things. [edit] Besides, as trq mentioned, it's a horrible script anyways.
-
1. Are you sure they're actually redirecting traffic to that location and not, say, setting the document root of the subdomain to be a subfolder under wherever the domain.com files are kept? (eg, /home/lucashermsen/domain.com/subdomain) 2. Do you have mod_rewrite installed? Just checking. 3. What does Apache's error log say about the 500 error?
-
Not those \w+s. I mean the ones with the colons. That you were asking about before. I'd still love to hear exactly what strings you're trying to match but how about /\[img(?:\s+width=(\d+(?:px|%)?)|\s+height=(\d+(?:px|%)?)|\s+src=([^\s\]]+))+\]/i Take a minute to look over that. $1 will be the width, $2 the height, and $3 the src. Possibly empty, like if one wasn't given. Then you can feed that to preg_replace_callback() like $new = preg_replace_callback('...', function($matches) { // need the src, width, and height to work if (!isset($matches[1], $matches[2], $matches[3])) { return $matches[0]; // unchanged } list(, $width, $height, $src) = $matches; // you may want to check for a valid width and height here // eg, is there a risk that someone will use width=9999999px? if (ctype_digit($width)) { $width .= "px"; } if (ctype_digit($height)) { $height .= "px"; } return "<img src=\"" . htmlentities($src) . "\" style=\"width: {$width}; height: {$height}\" />"; }, $old);
-
What are you aiming for? If it's "" then what are the :\w+ things for?
-
The "replace the white space after k" sounds like you want to remove it when it's at the end of the string (and maybe the beginning too). trim will do exactly that. Otherwise str_replace() isn't powerful enough and you need regular expressions. Exactly when should spaces be removed?
-
Only that first colon matters: it's a (?:...) where the first character inside is a colon. And if you didn't guess, a backslash can escape an otherwise important character. "[abc]" would be a character set while "\[abc\]" is literally a left bracket, "abc", and a right bracket.
-
Breaking down the number 20 into echo "2"; echo "0";
requinix replied to slyte33's topic in PHP Coding Help
If it's always (at least) two digits you can simply $number = "20"; echo $number[0]; echo $number[1]; -
Yep.
-
The & will almost always cause problems because of references. Can you do me a favor and post the output of print_r($document_tvs); print_r($docTVArray); right after the foreach?
-
There shouldn't be a reference at all. Remove the &. Are you sure $document_tvs doesn't contain the duplicate?
-
Top to bottom: * Al's 1:50am is technically correct because it won't protect you if you don't put quotes around the value. But his 2:15am and 2:17am posts are wrong. His "I would be doing crackers a favor" comment screams of newbness. * Not sure what Jeff Z was getting at. * Andy Powell suggestion to use MD5 is bad. Don't. * I didn't look at the class Andy mentioned. * Tony Arnold, foo, and Paul Dunderdale pointed out important typos. * matt's comment doesn't apply since there really shouldn't be multiple users with the same username. * I agree with Zac and Ryan S that using prepared statements just for sanitizing data is wasteful, but it is a perfect solution.
- 12 replies
-
- sql
- sql injection
-
(and 1 more)
Tagged with:
-
Wish I could edit... One change: \s Whitespace (spaces and tabs and newlines) \S Non-whitespace (opposite of \s)
-
1. It's alright, but you realize you're using the exact same define() in both branches? In any case there's a smarter solution if you want the hostname: define('BASE', $_SERVER['HTTP_HOST']); Then BASE will always be the hostname the person is visiting. 2. That's fine. People tend not to do that because it involves knowing the hostname, and inserting it into every link, but if you are more comfortable doing that then it's perfectly fine. ...Until you discover SSL.
-
The world of regular expressions is very complicated. Not something people can cover in an online forum. You should pick up a book (an actual book) on the subject; I believe the owl book is still the reigning champion. Meanwhile look for tutorials on Perl or PCRE syntax (and not POSIX). Eh, I'll type out the basics. It's like 99% of what you may ever need. Miscellaneous . Dot-all. Any character except newlines | Alternation. Either everything to the left or everything to the right. Can be limited to a group; can be chained Metacharacters \\ Backslash \d Digit \D Non-digit (opposite of \d) \n Unix newline (LF); \r\n is the Windows newline (CRLF) \r Mac newline (CR) \s Whitespace (spaces and tabs) \S Non-whitespace (opposite of \w) \t Tab \w "Word" character (lower- and uppercase letters, numbers, and underscores) \W Non-word character (opposite of \w) Character sets (most special symbols, like . and | and ?, lose their meanings; metacharacters still apply) [abc] Either 'a' or 'b' or 'c' [^abc] Neither 'a' nor 'b' nor 'c' [a-c] Either 'a' or 'c' or anything between them [-ac] Either '-' or 'a' or 'c' (hyphen becomes normal at the beginning) [ac^-] Either 'a', 'c', '^', or '-' (^ is only special at the beginning, hyphen becomes normal at the end) [a-c-f] Either 'a', 'c', something between them, '-', or 'f' (cannot chain ranges, hyphen becomes normal) Quantifiers (work on the preceeding single unit) X Exactly one of X X? Zero or one of X (ie, X is optional) X* Zero or more of X X+ One or more of X X{a} Exactly a-many of X (eg, {2} is exactly two) X{a,b} Between a- and b-many of X; either a or b can be optional (eg, {2,} is at least two) X*+ Possessive. Zero or more of X, as many as possible and no backtracking X+? Lazy. One or more of X, as few as possible Grouping and capturing (abc) Group "abc" together as one unit and capture it for later \N The N-th captured group, counting capturing (s from left to right $N Same as \N (?:abc) Group "abc" together as one unit but do not capture it Assertions/anchors (none of these capture or consume characters) ^ Beginning of the string $ End of the string \b Word boundary (between a \w and a \W) \B Non-word boundary (opposite of \B) (?=X) Positive lookahead. Ensure that X follows immediately (?!X) Negative lookahead. Ensure that X does not follow immediately (?<=X) Positive lookbehind. Ensure that X preceeded immediately (?<!X) Negative lookbehind. Ensure that X did not preceed immediately Flags /e Eval, preg_replace() only. Replacement string is evaluated as PHP code first. Deprecated in favor of using preg_replace_callback() /i Letters (besides \w) are case-insensitive /m ^ and $ can also match the beginning and end of a line /s Dot-all will match newlines /x Whitespace is ignored, line comments allowed See also the manual.
-
With a literal /č/g you'd have to worry about the file encoding (the file containing that code). If you look up the individual characters you want to replace in Unicode they'll be called "U+ABCD SOME TEXT DESCRIPTION" (where ABCD is a hex number). You can copy that number into a regex like /[\uABCD]/g Given that č is U+010D, ć is U+0107, š is U+0161, đ is U+0111, and ž is U+0173, /[\u010D\u0107\u0161\u0111\u0173]/g will match those five characters. As for exactly what you want to do with this information, I'm not sure either. Side note: I'm pretty sure there's no "Croatian" block in Unicode, otherwise this would be a lot easier. Also Javascript doesn't support the \p{} construct you can find in Perl and PHP/PCRE, so you can't specify complete alphabets (like how a \w represents [a-zA-Z0-9_]).
- 5 replies
-
- regex
- croatian letters
-
(and 1 more)
Tagged with:
-
Is there a better way to get the root server address?
requinix replied to The Letter E's topic in PHP Coding Help
No. Please don't worry about optimizing microseconds out of PHP code. It's a worthless endeavor. -
Okay, I would accept "because I'd like to try using regular expressions" as a reason, though only after I made sure you understood that a regex is not the solution to scanning an HTML page. But as it so happens regex is not a solution at all for this. The table is built entirely using Javascript, with JSON returned from Google Docs. The closest you could get would be running the regex against the JSON but it would be entirely ridiculous to try to construct something that would work as you'd want. Sorry but this isn't a problem you can use to learn regular expressions.
-
Well, the regex specifically says "SM_Folder" while your output has "SoMe_Folder", and the regex also expects "ID2PDF" where your output has "someFile". If you don't know those names for sure then use a wildcard. Also I'm removing the leading slash from the filename, just in case. /^Loaded options from XML file: '.*\/([a-zA-Z]{3})\/[a-zA-Z]+_Proof_\1\/processing\/.*_options.xml$/im When a regex doesn't match, make it more and more generic (more wildcards, fewer literal characters) until it matches. Then figure out what you may or may not need to add back to get the exact results you need.
-
Fortunately for you the source doc is public and accessible as CSV. https://spreadsheets.google.com/pub?key=0AnM9vQU7XgF9dHZvNXl1dHJqZ21oNmp4UklSU2RUYXc&output=csv You can use fopen+fgetcsv+fclose to read it.
-
We tried. We really did. She told you to use $nation, I told you to use $nation. I even gave you something you could have just copied and pasted. But then you turned around and showed us this weird code that works, sure, but really isn't that great. Certainly more complicated than it needs to be. It's great that you figured out a solution but it's offensive to us when you ignore what we say.
-
That sounds nothing like what you originally said.
-
The [a-zA-Z] you added will only match one character. You'd need a + to match more than one. $regex = '#^Loaded options from XML file: \'/.*/SM_Folder/([a-z]{3})/\w+_\1/processing/ID2PDF_options.xml\'$#im'; preg_match_all($regex, $text_from_file, $matches) && var_dump($matches); works for me (with the wonky quotes in the example text fixed).
-
You don't have to "decode" anything. The RewriteRule will turn those things into $_GET values for you but that'll only happen if you use the right URL in your links.
-
So you haven't changed anything... And you expect it to work differently?