-
Posts
50 -
Joined
-
Last visited
Never
Posts posted by fizix
-
-
what about this?
if (preg_match('/http:\/\/[^";\']+/im', $str, $regs)) { $result = $regs[0]; }
I'm afraid that wouldn't work for two reasons:
1. The address won't necessarily start with http://, it could be a relative address (sorry, should have specified that)
2. I only want to find strings that start with window.location=
-
Hey all,
I've been playing with this for a while and finally decided to ask the experts. I'm trying to match just the URL in the following strings:
window.location="http://www.text.com"; window.location='http://www.text.com'; window.location="http://www.text.com" window.location='http://www.text.com' window.location=http://www.text.com; window.location=http://www.text.com
This works for all of them except the last one:
/window\.location\=["\']?(.*?)["\';]/i
Is there any way to make a regex that works for all of them?
-
Is your data changing at all? If not you shouldn't even be using regex; you could use strpos().
-
It may be more efficient to read the whole string in to a PHP string and use square brackets to read each character, like so:
$string = 'abcdef'; echo $string[0]; // a echo $string[3]; // d
-
I use a function like this:
function parsesearch($search) { $searches = split(" ", $search); $searchqty = count($searches); for($x=0;$x<$searchqty;$x++) { if(!isset($searchquery)) $searchquery = " WHERE (title_keys.title LIKE '%".$searches[$x]."%' OR ips.domain LIKE '%".$searches[$x]."%')"; else $searchquery .= " AND (title_keys.title LIKE '%".$searches[$x]."%' OR ips.domain LIKE '%".$searches[$x]."%')"; } return $searchquery; }
You may need to tailor it to your needs but hopefully it gives you a starting point.
-
Does the password look like a string of numbers and letters before you change it? If so it could be an MD5 hash (or other hash). If that's the case you'd need to first encode the password to MD5 with a website like this one:
-
Your query should look like this:
$query = "SELECT tourname, lastname from events where tourname like '%$search%' or lastname like '%$search%'
Note where I added the $ to or lastname like '%$search%'.
-
Ok, I've got two tables:
Table: ips +-----------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+--------------+------+-----+---------+----------------+ | id | int(11) | | PRI | NULL | auto_increment | | connect | tinyint(1) | | | 0 | | | ip | bigint(20) | | | 0 | | | domain | varchar(100) | | | | | | title | varchar(250) | | | | | | time | int(11) | | MUL | 0 | | | title_key | int(2) | | | 0 | | +-----------+--------------+------+-----+---------+----------------+ 7 rows in set (0.00 sec) Table: title_keys +-------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+----------------+ | id | int(4) | | PRI | NULL | auto_increment | | title | varchar(250) | | | | | +-------+--------------+------+-----+---------+----------------+ 2 rows in set (0.00 sec)
I'm trying to LEFT JOIN the two tables so that title.title_keys becomes the title when ips.title_key matches id.title_keys. In all other instances I'd like it to return ips.title. I've made sure that ips.title is always empty when ips.title_key is not 0. Here is my query:
SELECT * FROM `ips` LEFT JOIN `title_keys` ON ips.title_key = title_keys.id
However, when I echo mysql_result($recentfound,$x,"title") it only echoes the title from ips.title. I thought if ips.title was blank and title_keys.id matched ips.title_key it would echo title_keys.title. What am I doing wrong?
-
one option would be to set a session variable (assuming you're okay with using sessions) that contains the total number of results (or pages). then when you go to run the procedure for storing the lastrun value, you can check the current page/limit against the stored maximum and decide from there. if you decide to update it, don't forget to clear the session variable so that future "new results only" queries experience no interference.
That's a good idea. I think I'll do something similar such as storing a session variable with the ID of the search that they're currently looking at. Then if they view a different search I'll just reset that variable (and of course it will be reset when they log out).
-
Ok, I thought this would be an easy one at first but it's turned in to something more complicated than I expected:
I have a database that can be searched and I allow my users to save their searches. I want to allow them to view all the new results since they last ran the search. That part is easy... I just save the timestamp for the last time they ran the search to a 'lastrun' column is SQL and update 'lastrun' every time the search is run. However, I run in to problems with multi-page results... When they move to the next page it thinks that the search was run a few minutes or seconds ago so page 2 is blank.
My question is: how can I tell when the user is done with his/her search so that I can update the 'lastrun' parameter?
-
Hi
If you could put up with them being non random it would be possible.
All the best
Keith
I don't want to create them sequentially but maybe if I assigned each process a group of IP addresses (say 2000 at a time) and then told it to select from that group at random and removed each address I tried from the group as I went it would still be quasi-random and they would all be unique...
-
Hi
If it a tricky one then.
IP address is just 4 numbers each from 0 to 255, so just really a 4 byte unsigned integer (or 4 unsigned tinyints). Not that large to store lots (you could store evey one possible in about 16gb). However possibly not manageable to search them each time.
Afraid I am not sure I can see a solution without storing them to check against duplicates.
All the best
Keith
I think you're right... I give up. :'(
-
you can use array_unique on your array of random numbers. Random number generators will run into duplicate entries at some point, so perhaps randomly generated numbers isn't what you want.
also uniqueid() seems to be exactly what you want as people have said.. why dont you use that?
Read UP ^
-
Hi
What do you need the string for that you need to control the length of it? Does it need to be random rather than just unique?
If you truely need a unique and random id of a specified length then I think you will have to do it by making a random one up and then checking it hasn't been used.
All the best
Keith
Yes, it needs to be random and unique. I'm basically generating a bunch of random IP addresses and I don't want to generate the same one twice. I can't keep a list of addresses I've already generated because I'll have multiple processes running at the same time and the database containing the addresses would get WAY too big WAY too quickly (trust me, I've already tried).
-
Hi
No, because it appears you are just using your loop to test when the number as a seed causes a duplicate.
If you just use the id then no need to use it as a seed or anything. Just use it as it is.
Why does the number need to be random? The suggestion of uniqueid() appears to give you exactly what you want without any need for any extra random number generation.
All the best
Keith
uniqueid gives me no control over the length of the string I'm generating, nor does it guarantee that I would have duplicates.
-
if you need something unique for your numbers.. generate an md5 hash for each integer
That didn't help. I changed my test function to this:
$test = array(); $starttime = time(); for ($i=0;$i<100000;$i++) { srand($i); if ($runtime % 30 == 0) set_time_limit(200); $number = md5(rand()); if (in_array($number, $test)) { die("Found dupe at iteration number $i<br />\nNumber is $number"); } else { $test[] = $number; } $runtime = time() - $starttime; }
And got:
Found dupe at iteration number 32768Number is 827ccb0eea8a706c4c34a16891f84e7b
Well then you could md5 it with random salts. Example:
$test = array(); $starttime = time(); for ($i=0;$i<100000;$i++) { srand($i); if ($runtime % 30 == 0) set_time_limit(200); $salt1 = rand(); srand($i + rand()); $salt2 = rand(); srand($i - rand()); $number = md5($salt1 . rand() . $salt2); if (in_array($number, $test)) { die("Found dupe at iteration number $i<br />\nNumber is $number"); } else { $test[] = $number; } $runtime = time() - $starttime; }
Still didn't work. :'(
Found dupe at iteration number 32768Number is 40be5f590f625b8cff8072df0026756d
-
Does anybody know of a way to generate a random number, without duplicates, and not log all the numbers that have already been generated?
If it is truely a random number then it will inevitably have duplicates.
Does it need to be a large and complex number? Or would just a count work? You could have a table with a single integer autonumber column and just do an insert (of NULL) and then get the last inserted key (in Oracle you could just use a sequence, but MySQL doesn't support them). To stop the table just delete old inserts regularly (possibly triggered by inserts to the table).
If you want to mix it up a bit then just hash that number.
All the best
Keith
Wouldn't this basically do the same thing as my for loop?
-
has uniqid() been deprecated or something? Otherwise surely this is the obvious function.
How can I use uniqid to seed the rand function?
-
Anybody else have any ideas?
-
if you need something unique for your numbers.. generate an md5 hash for each integer
That didn't help. I changed my test function to this:
$test = array(); $starttime = time(); for ($i=0;$i<100000;$i++) { srand($i); if ($runtime % 30 == 0) set_time_limit(200); $number = md5(rand()); if (in_array($number, $test)) { die("Found dupe at iteration number $i<br />\nNumber is $number"); } else { $test[] = $number; } $runtime = time() - $starttime; }
And got:
Found dupe at iteration number 32768Number is 827ccb0eea8a706c4c34a16891f84e7b
-
When finding a duplicate, just subtract 1 from $i and move on. That'll give you the required number of random integers.
Unfortunately I can't do this because I'll have multiple scripts running at the same time and none of them should be generating the same number. I can't store all the numbers in a database either... the database would get way too big way too quickly. Does anybody know of a way to generate a random number, without duplicates, and not log all the numbers that have already been generated?
-
I hope somebody can help me with this because I'm at wit's end:
I have a script that generates a random number. I don't want it to ever generate the same random number twice so I'm seeding the rand function with an incrementing number. However, after a certain point, it generates a duplicate random number anyway. Here's the function to prove it:
$test = array(); set_time_limit(200); for ($i=10;$i<100000;$i++) { srand($i); $number = rand(); if (in_array($number, $test)) { die("Found dupe at iteration number $i<br />\nNumber is $number"); } else { $test[] = $number; } $runtime = time() - $starttime; }
The output I get when running the script under Apache in Windows is this:
Found dupe at iteration number 32778Number is 16507
However, when I run the script in a Linux environment I don't seem to have the problem (although it times out before it gets to the 200 second time limit). Anybody have any ideas how to fix this?
By the way, you'll need to have "suhosin.srand.ignore = Off" in your php.ini file to the code above.
-
Does anybody have ANY ideas?
-
Ok, say I'm trying to pull tags from the source of
. When doing a print_r on $found I get:Array ( [0] => Array ( [0] => <object width='728' height='90'>"; url += "<" + "param value='clickTAG=" + encodeURIComponent(ref_url) + "' /" + ">"; url += "<" + "embed src='" + img_url + "'"; url += " type='application/x-shockwave-flash' wmode='transparent'"; url += " flashvars='clickTAG=" + encodeURIComponent(ref_url) + "'"; url += " width='728' height='90' /" + ">"; url += "</object> [1] => <object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/Ee_8IMx0uMo"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/Ee_8IMx0uMo" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object> ) )
However, I only want to get the result in $found[0][1], not $found[0][0]. I want to filter it out by excluding strings with semicolons [;] from the results.
Need to make one regex work for this scenario
in Regex Help
Posted
You're a genius! Thank you sir!