Jump to content

.josh

Staff Alumni
  • Posts

    14,780
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by .josh

  1. DOM solution is ideal for scraping html. But to address your problem with the regex, issue is you haven't told it to match anything except for the literal string "Currently Playing:" or "<b></b>". You need to use things like wildcards and quantifiers etc.. to create a pattern. For example, if you want to grab everything within <b>..</b> tag: preg_match('~<b>(.*?)</b>~i',$page_contents, $matches); So ~<b>(.*?)</b>~i is the pattern. Overall the goal here is to use the <b> and </b> as anchors, basically a way to tell the regex engine where in the string to look for something. Then we have (.*?) which will match for the stuff between those tags. ~ This is the pattern delimiter. All patterns must be wrapped in a delimiter, because preg_match has optional modifiers you can put within the first argument string. I included a modifier in this pattern so you can see (the "i" at the end). In your code you used / which is fine except if you need to use that character as part of your pattern, you will need to escape it, and closing html tags use /. So if you are making a regex to scrape html, it makes for cleaner patterns to pick some other delimiter. <b> Match for literal string "<b>". This is to tell the engine where you want to start matching ( Start of group to capture. Basically when you wrap part of your pattern in parenthesis, you are telling the engine to put what it matches in an additional, separate element in the returned $matches array. . This is a wildcard. It means to match one of any single character (except newline chars unless you tell it to w/ a modifier) * This is a quantifier. It says to match 0 or more of any of the previous character or group. So together .* means to match 0 or more of any characters ? This means to make the .* a lazy match. By default quantifiers are greedy. This means that they will match everything they can possibly match in the string and then start giving stuff back in order to satisfy the rest of the pattern. This isn't ideal a lot of times. Consider the string "<b>foo</b><b>bar</b>". If you have ~<b>(.*)</b>~i and your intention is to match stuff between the "b" tag, this will actually match everything up to the last instance of </b> : "<b>foo</b><b>bar</b>". So ? tells the quantifier not to be greedy, to only match one character at a time until it finds the first instance of the rest of the pattern. So ~<b>(.*?)</b>~i will match "<b>foo</b><b>bar</b>". ) End of group to capture. </b> Match for literal string "</b>". This is to tell the engine where to stop matching. ~ Ending pattern delimiter. i A pattern modifier. This tells the regex engine to do a case-insensitive match. So an example: $page_contents = file_get_contents("http://zixtyycraft.com/radio/song.php"); preg_match('~<b>(.*?)</b>~i',$page_contents, $matches); print_r($matches); This will print out the following: Array ( [0] => <b>The Chemical Brothers - Life Is Sweet (Daft Punk Remix)</b> [1] => The Chemical Brothers - Life Is Sweet (Daft Punk Remix) ) $matches[0] contains the full matched pattern, everything between the ~ pattern delimiters. $matches[1] contains everything in the first captured group, everything between the parenthesis (the (.*?))
  2. You can work yourself up to at least Guru membergroup status and be able to post tutorials yourself. Or you can submit to can submit the tutorial to us for review.
  3. You have 2 major issues to overcome here: 1) Figuring out which numbers should be multiplied and which numbers should not. At face value, you can do something like... $content = preg_replace("~\d+~e",'$n*$0',$content); ..where $n is the multiplier. But that isn't really context specific. So for instance if you happen to have other numbers within your content that aren't ingredient measurements, they will be affected (eg: "...cook at 300 degrees" would turn into "...cook at 600 degrees"). 2) Working out measurements given as fractions or decimals. For example, if you have "1/2tsp salt" you will end up with "2/4tsp salt", or "1.5tbsp butter" would make for "2.10tbsp butter". How you solve this mostly depends on how you have your content coded to begin with. Do you have control over how your content is coded? For example, can you wrap some kind of tag around all instances of numbers that should be multiplied? If so, then figuring out issue #1 would be easy. But if not...I'm afraid there's probably no accurate way to do that. You might possibly be able to do something with the ingredient list because it might be wrapped in a separate html div or have list tags wrapped around it or something, but probably not within the instructions. Show some examples of real content (the actual html code). As for working out #2...well that's largely dependent on #1, but in general, even if you could isolate which numbers should be multiplied, decimal to fraction conversions (or visa versa) isn't exact (for instance, 1/3 makes for 1.3333....infinity more 3's. You can round off easy enough but..go ahead and try finding an easy, accurate way to convert that back to 1/3!)
  4. It is very unlikely you will be able to set something better up "at home". You can probably get a better deal on the server hardware, but as far as an internet connection... most residential ISPs have it in their ToS that you are not allowed to use your internet connection for servers, and even if your ISP doesn't specifically state that (or you chance it and hope not to get caught), the actual connection for residents are usually much slower than commercial connections. If you are hosting some small site and only expect a few hits here and there...then residential connection will probably be okay (providing your ISP allows it). But if you are running some site and expect a lot of traffic and bandwidth...forget it.
  5. In and of itself, the function works fine in IE8. Clicking on something that calls your function clears it just fine. Here is test code I used: <script type='text/javascript'> function UnCheckRadios(radioButtonGroupName) { var formName = "frmOrder"; var form = document.forms[formName]; var noOfRadioButtons=form[radioButtonGroupName].length; for(var x=0;x<noOfRadioButtons;x++) { chk=form[radioButtonGroupName][x].checked=false; } } </script> <form name='frmOrder'> <input type="radio" name="colors" id="red" />Red<br /> <input type="radio" name="colors" id="blue" />Blue<br /> <input type="radio" name="colors" id="green" />Green<br /> </form> <button type="button" onclick="UnCheckRadios('colors')">uncheck</button> Look at the output of your form radio buttons, make sure that your php script is outputting what it is supposed to be outputting (the right radio button names). Also make sure your form is named "frmOrder".
  6. read stickies.
  7. fyi, DOM is a better method.
  8. To directly answer your question, no there is no server-side way to determine what plugins a user has installed in their browser. It is possible to do some detection client-side with javascript, and either pop a hidden field to send to server, submit info via ajax or just output message directly with javascript. However, all these things are easy to get past anyways, and in no way really hinders the points stated by others. In short, you are approaching this issue the wrong way, look into advice already posted (ask for details if you don't understand)
  9. IMO those shouldn't count as the same. OP: Are you sure you want something like "studying" to count for "study"? If so, there's no real easy way around that, other than to allow for false positives (like requinix's example), unless you basically make a lookup table of all tenses/forms of a given word to check for, in addition to the actual word you're looking for. Anyways, here is a non-regex approach that may or may not be faster... (which also allows for false positives) $file = "I went back home to see my family as I was studying in China. By the time I arrived home I was so hungry and the weather was cloudy."; $words = array("see", "reader", "study", "China", "cloudy", "hungry", "answer"); foreach ($words as $word) { $results[$word] = (stripos($file, $word)!==false) ? 'yes' : 'no'; } // print out results print_r($results); output: Array ( [see] => yes [reader] => no [study] => yes [China] => yes [cloudy] => yes [hungry] => yes [answer] => no )
  10. Is tracking people in a secretive way a correct/moral thing to do? (I don't think so) There is no secret about it. We're plainly talking about it, aren't we? Well I am "shocked". Again, why would anybody other than a retard think the internet should be this magical experience where everything is easy to do according to their individual ways of going about things, and get it all for free etc... and not pay a price somewhere along the line? Yes, I am shocked at how many people out there really do expect others to simultaneously be psychic and ignorant about them. Before the age of the internet business's forked out 1000's on advertising in the yellow pages... etc. Having an internet presence as a business is essentially advertising period, so I doubt they would ask for money to access your site. If you really think you were getting your yellow pages for free then you are being ignorant. You paid for it indirectly, I promise you. Companies pay to have their business listed in the yellow pages. They pass that cost on to you by what they charge you for their products/services. Back then, you simply paid for this stuff more directly (or more accurately, you paid for it less indirectly than now). These says with technology being more complex, there's a lot more moving parts, a lot more people involved between you and the business when it comes to things like websites or being online, so there are more opportunities to lower the price of products and services - providing we stop being whiny bitches about being tracked. Also, having an an internet presence as a presence is not just advertising. And btw, there are plenty of sites who ask for money to access their site. Hello, Netflix and the like? favoritpronsite.com? Music/radio sites? "Help" Services? Sure, they have a "free" area where you can browse services offered but they are not 100% free! Oh I get it, you meant random joe local business. You really don't think they aren't somehow paying for that site by passing that cost on to you? There is nothing free about the internet and we, the consumer, ultimately pay for it, whether directly or indirectly. That is how it has always been and always will be, regardless of whether it is the yellow pages or telemarketing calls we hate or websites or tv ads or anything else. Anything that cannot be paid for somewhere indirectly along the lines, will be paid for by the cost of the product itself. I think maybe you misread whatever article you read or left something important out, because at face value this statement is retarded. How else would FB be able to let you enter in contact info in your profile and have you able to edit it later or share with your friends, except for to store it? And anyways, I'm sorry to be the informer of bad news for you, but the "do what you can get away with" mentality is nothing new and nothing specific to FB. That is how the world works. I'm not saying that is right, but that's how it is. Morality is decided by law, which is written by corporations. But we can say that, by looking at history and how sites came to grow and be more accessible in the first place, and by looking at the money made from companies directly trying to sell you something, whether they got the money directly from you or indirectly. And by looking at the companies who have thrived from tracking you. We get to look at their paper trails and see that this does work, and people are happy with the results they get out of it...the problem is that people tend to get all hypocritical and stupid about it when they sit down and think about it. People want this stuff. They want to be able to go to a site and it be designed to easily do xyz. They don't want to have to pay a million different people a fee to even get online etc... and no, nobody should have to give you something for free! Why don't you try running your own business for a while and see how that goes! That's right. We never know do we. If you somehow think you'll sleep better at night knowing that places like FB can't share info with others for some nefarious purpose... if you're going to be all conspiracy theorist about it, I assure you, "the man" doesn't need to ask FaceBook where you live or what your phone number is. Again, people make out like this "privacy" thing is a way bigger deal than it is. They hear that sites are tracking them and for some unknown stupid reason they imagine their cc, ss, id, phone #'s being shared with lots of people everywhere. Or that some shadow agency is getting ready to totally take over your identity and fuck you over. Are there baddies out there trying to do that sort of thing? Sure. But that's why you avoid shady sites to begin with. If you walk down a dark alley, chances of you getting mugged go up. But what's worse is how some people even bitch about random non-personal shit like how many times "a" page was viewed by "people". I mean come on man, sit down and have a serious thought exercise about what exactly is your problem with all this. If you know that people use this stuff to make things more convenient for you, make things more relevant for you... what exactly is the problem? It "feels" wrong. It "seems" wrong. You need to do better than that. Especially when you're playing the "lack of morals in general" card, because as mentioned, those sorts of people...while they may or may not be legit concerns...do not need people like facebook or tracking cookies to fuck you over.
  11. Haha. You all seem to think that I hate companies profiling its customers. No. I just don't like them profiling me after I have left the premises. I'd love to see any one of you accepting having someone walk along behind you with a clipboard making notes about what you do and where you go after you have left a shop. I think after about 5 minutes you would turn around and confront the person. "Someone" does follow you around from store to store. It's call "Mr. Credit Card." Every time you swipe that card, your cc company records that, and they send that shit to all of its partners and affiliates. Even when you walk out of walmart and go somewhere to eat, Walmart will know. And not just credit cards. Even your bank's checkcard or any other "card". It's all really more or less the same thing. "AAh but I pay with cash only!" you say. So that affords you a little bit of anonymity, good job. But how long do you think that will last? Already many places do not accept cash at all. And even still, most people use a card of some kind already, even if cash is accepted. Facebook (or any other site) can't track all of your browsing history. They can only track pages on other sites that have some actual code on it, like facebook api for liking/sharing an article or posting comment, etc... That is the magic code that makes it possible. Without it, facebook cookies are just that - cookies. Cookies can't do anything in and of themselves. And why shouldn't FB be allowed to track this? At this point in time, you should really be bitching at the website you are on, not FB, but even then, it is your choice to go there and that website has a vested interest in trying to track you just the same. All those form fields with "personal information" they have to fill out mean jack shit to them if nobody is filling them out or when they do, they purposefully misinformation them. And yes, lots of companies have a FaceBook page...but do you really go surfing around FB looking for them? How many people do you know do that? Since when did FB replace Google? Nobody does that. And people bitch about those things too! You point at things you know are useless and claim that is enough for them. More trying to have your cake and eat it too. And even still, who are you to say that you should be able to walk into someone else's house and not be tracked or identified? Again I say, the only people with that mindset are thieves, trolls, cheats, scammers, people trying to cheat the system or other people. I'm not trying to bitch at you or single you out personally. My rants are in general. But as for you specifically, responding to your post specifically, I can see that you do acknowledge some costs involved, and acknowledge on some level why you are being tracked, but there are literally a million moving parts here.... it's not just what you are paying your hosting service to keep your website online. Bottom line is that all day long people try to have their cake and eat it too when it comes to being online. People bitch about having to pay a bill to a dozen different companies just to get online in the first place. They bitch about having to give their payment info to any site out there instead of a single trusted location. They bitch about getting bombarded with ads for things they don't want. People bitch when it's hard to fill out a form or read some article because fonts are fucked or some other UX flaw. People bitch when they have to jump through a bunch of hoops to make a post somewhere. People bitch and bitch and bitch and bitchbitchbitch about all this shit, and then bitch some more when companies try to do something about it. Like I said... people want to have their cake and eat it too. We somehow think the internet should be this super awesome experience where everything is magically exactly how we want it to be, no guesswork or baddie anythings, and most importantly, no having to pay for anything. In short, people seem to expect the internet to be heaven. Well it's not. The truth is that nobody is psychic, and nothing is free. People need to be able to identify you in order to do anything. That's how the system works, both in the real world and online. They are going to identify you one way or the other. We need to look at the bigger picture, start realizing that it's a lot of moving parts. No, companies like FaceBook do not directly need to know our activities or interests etc.. . but other companies do, and this is about connecting different investors and stakeholders together so that they can keep from making us have to jump through all those hoops that we bitch about.
  12. Hate to break it to you, but facebook is by far not the first site to continue to track your activities on their site, even after you "log off". The only thing really "concerning" about this is people who use public computers..but then, even that is nothing new. You should never use a public computer to login to really private stuff to begin with (like your bank). But if you do use it for logging into things like facebook (or something else "private" but not as private as logging into your bank website), you should always make sure to delete all cookies and history before you leave the computer. This is not new.. Here's the thing. Companies spend lots of money investing in their website. They pay people like us to design and build their website. It is an investment to get people to buy their product or get people to engage in xyz or give a shit about ads or whatever their goal is, depending on what the product/service is. Then they pay other people to track what visitors are doing on the website. And why do you suppose you are being tracked? It is so they can try and figure out what parts of their site people like and what parts people don't like, and improve their site. Additionally, they want to be able to show you ads or other content relevant to you so that you will be more inclined to engage with them. And usually the deal with targeted ads is because you aren't paying for their service to begin with. Notice how most sites make them go away when you give them money some other way? Is trying to improve your experience and indirectly offset their cost to bring you said experience on their site really such a bad thing? I swear, people make out like there is some evil plot afoot when it comes to being tracked online, just waiting for guys in suits to come knocking on your door after they find out you like blue socks or some shit. Really?? The worst thing that happens is that FaceBook sees you like a particular product and they go out and tell the advertisers that you like productX so the advertisers start offering you stuff about productX. Is that really a bad thing? "Oh nohs, someone offered me a deal on something I might actually be interested in! IT'S THE END OF THE FUCKING WORLD I TELL YOU!!!!" Are people really that into having people try to sell random shit to them they will never want? Is this how we act in the real world? Do we walk into Walmart and start bitching because they have security cameras up? Because I'll let you in on a little secret: physical stores do the same thing. You don't really think those security cameras are there just to track potential thieves do you? Companies look at them to evaluate the paths people take through their store, what products people actually spend time browsing, etc.. and reorganize their store accordingly. But do we complain about this? We are fucking ourselves because we refuse to look past ourselves and why we are being tracked in the first place. We seem to have this idea that the internet should be a place where we can completely and anonymously act however we want to act and do whatever we want to do without being identified in any way whatsoever and not have to account for said actions. Oh and we also seem to think that it should all be free. Why is this? The only people I can see who stand to actually benefit from this scenario are people who want to exploit, troll, cheat, steal, etc.. the system or other people. But as for people who aren't trying to cheat the system or others... why do you think the cost of things like getting online to begin with are going up? Running servers and websites and all the technology used to even get people online is not free and therefore it will never be free to us. Whether we pay a million different people in order to have an online experience, or reduce it to a handful of people or even one person (and then everybody else get their piece of the pie through them) ... which sounds more convenient to you? But all those people can't offer you this "free" experience and get their piece of the pie from someone without your "paper trail". We have to realize that the more we bitch about things like "privacy" and shit, the more we are going to just have to pay for things more directly. Our ISP costs will go up. Sites will either stop having an online presence or they will make you pay to access them. Is this really what we really want? We seriously need to stop bitching when someone takes note of which page we are viewing on their site, and look at the bigger picture. And I really hate having to defend companies like this. Lord knows, they certainly are ripping us off on lots of things as it is. But once again I'm being forced to play devil's advocate because people are being frakking stupid about shit, not realizing they are just fucking themselves over in the long run by bitching about the wrong things. Pick your battles people!
  13. it's because the /-_ part of your negative char class is being interpreted as a range of chars between / and _ you need to either escape the hyphen or put it at the beginning or end of the list.
  14. you will need to use curl instead of file_get_contents, to automate setting cookies and logging into the member area.
  15. If you are just wanting to open up and grab all contents of file in one go then yes, use file_get_contents. But for large files this isn't a good thing to do, as it it puts the entire content of the file into memory. What you would do instead depends on what you are trying to do in general. If you are parsing lines in a file then you would use fread to read and process one line at a time. If you are trying to search or update lines or otherwise use as a flat-file database...consider using a database instead. Or if that's not an option, consider using mysql-lite.
  16. yah, cookie is probably a good way to go. For reading and setting a cookie, you can grab a couple of functions for that here. And then basically on your page(s), you would have something like // if cookie doesn't exist, set cookie and redirect user if (getCookie("cookieNameHere") != "redirected") { // set a cookie named cookieNameHere with a value to look for, to expire in a year. // it doesn't really matter what you name the cookie as long as you don't name it some other cookie name being used on your site(s). // it doesn't really matter what value you set it as, as long as you set it with something and look for that same something later. // how long you set the cookie is up to you, based on your own timelines setCookie("cookieNameHere","redirected",365); // redirect user to new site location.href = "new site url here"; }
  17. are you using a javascript framework on your old site, like jquery, mootools or prototype?
  18. There are other functions that specifically handle parsing URL strings; here is a non-regex approach. I'm not hatin' on regex (I love regex) but you should avoid using regex when possible, because most people aren't that great with regex, and so it makes it that much harder to maintain or expand code. // url to parse $url = "http://search.yahoo.com/search;_ylt=A0WTfYQKqWlO.FYA2CibvZx4?fr=yfp-t-701-s&toggle=1&cop=mss&ei=UTF8&p=keyword"; // list of url params you want to look for. Code below will return value of first one found $param_list = array('p','q','qt'); // parse the URL and get its components $comp = parse_url($url); // get the host $host = $comp['host']; // parse the query string and return an associative array of all query string params parse_str($comp['query'],$params); // attempt to find value of one of the query string params from your list foreach ($param_list as $k) { if (array_key_exists($k,$params)) { // Your regex doesn't show that you care which param was found, // but if that need changes, then $k is the param that was found // assign the value of the found param to $keyword $keyword = $params[$k]; break; } } echo $host; // 'psearch.yahoo.com' echo $keyword; // 'keyword'
  19. pfft...most regex engines do not support variable length lookbehinds, and the few that do are very clunky and slooow at best.
  20. Alternative, using zero-width assertion instead of captured groups: $post = '..'; $post = preg_replace('~\B:\)\B~', '<img src="smile.png" />', $post); echo $post;
  21. perhaps the big.com domain or its mail server has been used or is being used by other emails flagged as spam, so google may have them flagged as going to spam. There is nothing you can really do about that except find a more reputable host to host your stuff on.
  22. And all it takes is one person to spend 2 seconds with a scanner and some software to put it back to text form. And from there it gets distributed just the same. This is why people focus on freely distributing stuff like this, and focus on making money from performing some sort of service. IOW: move away from product and move towards service.
  23. http://www.phpfreaks.com/tutorial/php-add-text-to-image But on a personal note... I suggest you rethink doing this...
  24. there isn't really any kind of standard...perhaps if you post an example of what you are having trouble with, we can help? Also, usually a tech doc will have markup, naming, coding, etc.. conventions of the doc listed somewhere within the doc, sort of how like a map has a legend.
  25. @sasa: sure, checking for presence of characters NOT acceptable is an alternate way to go. However, it looks like you just c/p'd his base pattern, which doesn't match what he actually says he wants to match for. He says hyphens are acceptable, and he did not mention single quotes. @adam84: FYI neither of these addresses a couple of issues that are commonly addressed with. - These regexes do not account for length limits. Most sites want a name to have a minimum amount of characters, or at least limit the maximum. - These regexes do not prevent values like "---------" or " " or "- - - - - -" or ".....---.-- ---" or...you get the picture.
×
×
  • 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.