-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
looping through a database & exploding each field
.josh replied to Malevolence's topic in PHP Coding Help
because there is a comma between them. The comma counts as a character position in the string. Character Position:123456789 String:0,1,1,3,2 -
google the gutenberg project. They have practically everything public domain. At one point in time I got a text file of all the words or the words with their part of speech. Not definitions though. Wasn't looking for definitions. I may have those laying around somewhere, if that's all you're looking for.
-
looping through a database & exploding each field
.josh replied to Malevolence's topic in PHP Coding Help
Okay say your string is 0,1,1,3,2 with mysql's substring, the first character position in the string is 1 (not 0 like with most things). So you know that your numbers will be in positions 1,3,5,7,9,etc... so if you want to select all rows where the 2nd and 3rd numbers are 1 (from your OP), you would do something like this: select * from fs_pages where substring(pgFlags,3,1) = 1 and substring(pgFlags,5,1) = 1 -
[SOLVED] How to cut a string into multiple variables?
.josh replied to lopes_andre's topic in PHP Coding Help
explode will explode the string at the semicolons, and put each item into an array. Example: $string = "[email protected]; [email protected]; [email protected]"; $email = explode(";",$string); However, if there is also a space after the semicolon, each email is going to have a leading space. If you are 100% sure that there will always be a space, you can include the space in the explode like so: $email = explode("; ",$string); If you are not 100% sure (as in, it may or may not have a space), you can either loop through the array and trim each element, or you can instead, use preg_split, making it optionally match the space, like so: $email = preg_split('~;\s?~',$string); Understand that all of these methods makes an array, so does not make like $email1, $email2, $email3, etc... it makes $email[0], $email[1], $email[2], etc... -
looping through a database & exploding each field
.josh replied to Malevolence's topic in PHP Coding Help
Is your list of numbers are always single digits, so you know the substring position of each number? If so, you might be able to make us of mysql's substring -
[SOLVED] How to cut a string into multiple variables?
.josh replied to lopes_andre's topic in PHP Coding Help
so you want to split at semicolons or commas? -
You need to be able to check what's around it without actually matching anything, so that the other instances will be able to have something to match against. Lookaround to the rescue! $string = preg_replace('~(?<!"\w ){ (\w) }(?! \w")~',"X $1 Y",$string);
-
What do you usually do with a puzzle piece when trying to figure out where it goes?
-
Detectives usually start their investigation at the crime scene.
-
so...why can't you use a different session variable? You can have as many session variables as you want.
-
function someFunc () { // example 1: $count = func_num_args(); for ($x = 0; $x < $count; $x++) { echo "Argument $x : " . func_get_arg($x) . "<br/>"; } // example 2: $args = func_get_args(); foreach ($args as $n => $v) { echo "Argument $n : $v"; } } someFunc(); someFunc(100); someFunc('abc',123); someFunc(1,true,"omg",'x',1234,$blah);
-
+ is javascript . is php
-
So just pull it once, at the login page or whatever, and pass it to each page a different way. Depending on your needs, any one or more of those alternatives might work best for you. Just depends on your setup and goals. Session vars are the most common method; I suggest looking into that first.
-
$page = (int) ($numpeople / 15);
-
Data persistence. Variables do not persist from page to page unless you pass them somehow. You can -store/retrieve the data from a db on each page -store/retrieve the data from a flatfile on each page -store/retrieve the data from a a cookie -store/retrieve the data from a session variable -pass it to the next page via GET or POST method, using links, forms or header redirects
-
preg_replace is used to replace one thing with another. If you want to capture stuff, use preg_match or preg_match all. Your pattern would be ~-[^-]*-~
-
~\s?by\s?\w+$~i 1) no reason for ~ over # except that's my delimiter of choice. 2) the \s at the beginning is to account for the space before by, in your string. Otherwise there will be an extra space. It will return for example, "one is two " The ? is more of a precaution than anything, for that space. If your data somehow ends up looking like this: "one is twoby three", the pattern will not work, because it expects to match the preceding space. If you know for sure that that won't happen, then you can remove that first ?. 3) The same can be said for the 2nd ? as well. the pattern expects a space to be between the y and next word character. If for some reason its not there, the pattern won't match. If you know that this will not ever come up, you can remove the 2nd ? as well. 4) \w+ The + replaces the {1,100} it is the wildcard you asked for. It means "one or more of the previous thing". You can use * instead of + to do zero or more word characters. If you want to limit it to a specific range, then you need to stick with {x1,x2} 5) You used \S that means anything that is not a whitespace character. Well you don't need that. \w{1,100} or \w+ matches all of your non-whitespace characters, because it only matches a-z, A-Z, 0-9 and _ 6) $ tells the engine that after however many \w's match, an end of line must occur. So, when the pattern matches the "by blah" in the middle of the string, the pattern fails in the end, because a \n must come after it. 7) the ~....~i (the "i") means make it case insensitive. That is for in case "by" is spelled "BY" or "By" or "bY". If you do not expect that to happen, you can remove the "i".
-
The only place I see you assigning anything to $emails is this while loop: while ($row = $result->fetch()) { $emails = $row['email']; $name['name'] = $row['first_name']; } and you aren't assigning an array to it or assigning it as an array or anything, so when it gets to your foreach loop, $emails is just a variable, not an array. Perhaps you meant to do $emails[] = $row['email']; ?
-
preg_replace("~\s?by\s?\w+$~i", "", $title);
-
substr is only good for string extraction if you already know where to start and end. Extracting things between "a" and "b" is what the regex functions are for. $string = "what, he said that -100"; preg_match('~,\s?(.*?)\s?-~',$string,$match); // example to see the extracted info echo "<pre>";print_r($match);
-
post your query.
-
Well, I notice in your posted code, you pass $allow to your function. I used $allowed. Since it looks like you copied the code verbatim, did you make the necessary alterations, elsewhere?
-
Alternatively...since the issue is that the image is really a php file generating an image and sending it as a raw image to the browser, you could have your script save the file on the server as blah.jpg instead of outputting it, and then have the script redirect to the saved image.