Jump to content

DamienRoche

Members
  • Posts

    282
  • Joined

  • Last visited

    Never

Everything posted by DamienRoche

  1. It's because this says everything BUT: preg_replace('/[^a-zA-Z0-9]/', '', $panswer) You need to put the whitespace char type in there: \s So I think it should be: preg_replace('/[^a-zA-Z0-9\s]/', '', $panswer) Change your other preg_replace if need be as well. Hope that helps.
  2. I know I can use glob to list files and files within directories etc. but is it simple enough to just list every directory and every file? Thanks.
  3. Sorry, I sussed that out. I had a few issues so I've edited the original post to reflect my real problem. I have also tried $match[1]; but that didn't work. Thanks.
  4. I am having trouble understanding this. Here is my code: $html = "blah blah <strong>what.what = huh?</strong> blah blah"; preg_match('#<strong>what.what = huh?</strong>#', $html, $match); echo "<br>match: $match[0]"; The bit inbetween the strong tags will be extracted using a wildcard, so how would I go about escaping special characters? Any insight on this is welcomed. Thanks.
  5. Yeh, the first step would be understanding POST forms. so, create your form: <form action="thispage.php" method="post"> <input type="text" name="username"/> <input type="password" name="pass"/> <input type="submit"/> </form> so that's your basic login form. It will just have two input boxes and a submit button all on the same line. Appearance doesn't matter right now. What you want to do is get whatever you put into those boxes and them shove them into a variable - which is the most important concept of php. Variables are *everything*. here is how you would get username into a variable. $user = $_POST['username']; now that would go straight above your form because you are submitting your form to the same page. Then, you have to learn a little validation...which means an if statement, at least. So, check if a username has been added...if it has, continue, if not, end or return with a message: (remember $user from before) 1 if ($user != "") { 2 //continue - run the script 3 } else { 4 //display the form so, line 1-3 says --- if $user is not blank do whatever is in between { and } line 3 has else, which obviously means if $user is anything but blank, display the form. This is validation at it's most basic. Any way, this is how the final script would look. All the same file. <?php $user = $_POST['username']; if ($user != "") { //continue - run the script } else { //display the form ?> <form action="thispage.php" method="post"> <input type="text" name="username"/> <input type="password" name="pass"/> <input type="submit"/> </form> <?php } ?> Just copy and paste that into a file and have a little mess about with it. I really hope that helps at least a little bit. You'll get the hang of it eventually.
  6. Fantastic...these regex's are numbing my mind. I do have another question. I know you can use \b to indicate an exact word but how do I use it with the ^ anything but I just discovered. Example (won't work): <?php $string = "numbers = 21,200"; $number = preg_replace("/[^0-9\,|\bnumb\b]/", "", $string); echo $number; ?> or: <?php $string = "numbers = 21,200"; $number = preg_replace("/[^0-9\,]|\bnumb\b/", "", $string); echo $number; ?> It just keeps pulling numb from numbers. Thanks again.
  7. Have you tried case "/bana(.*?)/" Hope that helps.
  8. I'm totally confused here. I have this: $string = "numbers = 21,200"; $number = preg_replace("/[^0-9]/", "", $string); This outputs: 21200 But I just don't get it. My understanding is that it is saying - replace all 0-9 with nothing and use string as the subject. does the ^ indicate everything but? Finally, can anyone help me to not filter out the comma? As always, any help or advice is very much appreciated. Thanks.
  9. Hey, thanks for the reply!- sure enough, that code works, but for some reason isn't working for this: <?xml version='1.0' encoding='UTF-8'?> <ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:yahoo:srch" xsi:schemaLocation="urn:yahoo:srch http://api.search.yahoo.com/SiteExplorerService/V1/InlinkDataResponse.xsd" totalResultsAvailable="40626" firstResultPosition="1" totalResultsReturned="50"> <Result> <Title>Time Inc. Portal - Pathfinder: Your Guide to the Websites of Time Inc.</Title> <Url>http://www.pathfinder.com/</Url> <ClickUrl>http://www.pathfinder.com/</ClickUrl> </Result> <Result> <Title>The Big Picture</Title> <Url>http://bigpicture.typepad.com/</Url> <ClickUrl>http://bigpicture.typepad.com/</ClickUrl> </Result> <Result> <Title>Essential Links</Title> <Url>http://www.el.com/</Url> <ClickUrl>http://www.el.com/</ClickUrl> </Result> <Result> <Title>SaveOnRefinance.com</Title> <Url>http://www.saveonrefinance.com/</Url> <ClickUrl>http://www.saveonrefinance.com/</ClickUrl> </Result> <Result> <Title>Managerial Accounting Fundamentals Website</Title> <Url>http://members.tripod.com/Acct202/</Url> <ClickUrl>http://members.tripod.com/Acct202/</ClickUrl> </Result> <Result> <Title>The Big Picture</Title> <Url>http://bigpicture.typepad.com/comments/</Url> <ClickUrl>http://bigpicture.typepad.com/comments/</ClickUrl> </Result> <Result> <Title>Investor Home</Title> <Url>http://www.investorhome.com/</Url> <ClickUrl>http://www.investorhome.com/</ClickUrl> </Result> <Result> <Title>Backlash</Title> <Url>http://www.backlash.com/</Url> <ClickUrl>http://www.backlash.com/</ClickUrl> </Result> <Result> <Title>Time Inc. Portal</Title> <Url>http://cgi.pathfinder.com/</Url> <ClickUrl>http://cgi.pathfinder.com/</ClickUrl> </Result> <Result> <Title>The Big Picture | The Costanza Energy Policy: 25 Ways to Drive Oil to $150</Title> <Url>http://bigpicture.typepad.com/comments/2008/05/how-to-drive-oi.html</Url> <ClickUrl>http://bigpicture.typepad.com/comments/2008/05/how-to-drive-oi.html</ClickUrl> </Result> <Result> <Title>The Big Picture | DRM Crippled CD: A bizarre tale in 4 parts</Title> <Url>http://bigpicture.typepad.com/comments/2005/10/drm_crippled_cd.html</Url> <ClickUrl>http://bigpicture.typepad.com/comments/2005/10/drm_crippled_cd.html</ClickUrl> </Result> <Result> <Title>Global Satellite Chart--Geo-Orbit Quick-Look--Western Hemisphere--C/Ku ...</Title> <Url>http://www.geo-orbit.org/</Url> <ClickUrl>http://www.geo-orbit.org/</ClickUrl> </Result> <Result> <Title>Torrid Technologies, Inc.</Title> <Url>http://www.torrid-tech.com/</Url> <ClickUrl>http://www.torrid-tech.com/</ClickUrl> </Result> <Result> <Title>Welcome to HouseList Free Real Estate Listings</Title> <Url>http://www.houselist.com/</Url> <ClickUrl>http://www.houselist.com/</ClickUrl> </Result> <Result> <Title>Seven Mile</Title> <Url>http://frankschilling.typepad.com/</Url> <ClickUrl>http://frankschilling.typepad.com/</ClickUrl> </Result> <Result> <Title>Making money mistakes? Take our quiz! - Today Technology &amp; Money ...</Title> <Url>http://www.msnbc.msn.com/id/6779198/</Url> <ClickUrl>http://www.msnbc.msn.com/id/6779198/</ClickUrl> </Result> <Result> <Title>Jay's Pop Music Pages - Artists, Radio &amp; TV, Music Stores, Record ...</Title> <Url>http://www.stormloader.com/popmusic/home.htm</Url> <ClickUrl>http://www.stormloader.com/popmusic/home.htm</ClickUrl> </Result> <Result> <Title>The Big Picture | The NonGuidebook Version of What to Do (and Not Do ...</Title> <Url>http://bigpicture.typepad.com/comments/2008/05/guide-for-new-y.html</Url> <ClickUrl>http://bigpicture.typepad.com/comments/2008/05/guide-for-new-y.html</ClickUrl> </Result> <Result> <Title>Own, Be Owned Or Remain Invisible.</Title> <Url>http://www.irational.org/heath/_readme.html</Url> <ClickUrl>http://www.irational.org/heath/_readme.html</ClickUrl> </Result> <Result> <Title>MONEY Magazine: Best places to live 2007: Top 100</Title> <Url>http://money.cnn.com/magazines/moneymag/bplive/2007/top100/</Url> <ClickUrl>http://money.cnn.com/magazines/moneymag/bplive/2007/top100/</ClickUrl> </Result> <Result> <Title>Magazines - Grizzly Web Links</Title> <Url>http://grizzlyweb.com/links/magazine.asp</Url> <ClickUrl>http://grizzlyweb.com/links/magazine.asp</ClickUrl> </Result> <Result> <Title>The Big Picture | Countries GDP as US States</Title> <Url>http://bigpicture.typepad.com/comments/2007/01/countries_gdp_a.html</Url> <ClickUrl>http://bigpicture.typepad.com/comments/2007/01/countries_gdp_a.html</ClickUrl> </Result> <Result> <Title>4 Insurance Agents</Title> <Url>http://www.4insuranceagents.com/</Url> <ClickUrl>http://www.4insuranceagents.com/</ClickUrl> </Result> <Result> <Title>Christian Money</Title> <Url>http://www.christianmoney.com/</Url> <ClickUrl>http://www.christianmoney.com/</ClickUrl> </Result> <Result> <Title>Digital Librarian: Reference</Title> <Url>http://www.digital-librarian.com/reference.html</Url> <ClickUrl>http://www.digital-librarian.com/reference.html</ClickUrl> </Result> <Result> <Title>Ten things to save money in 2004 - Today Technology &amp; Money - MSNBC.com</Title> <Url>http://www.msnbc.msn.com/id/3841990/</Url> <ClickUrl>http://www.msnbc.msn.com/id/3841990/</ClickUrl> </Result> <Result> <Title>Fed cuts help...sort of - Aug. 21, 2001</Title> <Url>http://money.cnn.com/2001/08/21/home_auto/q_rates/</Url> <ClickUrl>http://money.cnn.com/2001/08/21/home_auto/q_rates/</ClickUrl> </Result> <Result> <Title>TIMEasia.com | TIME 100: Sun Yat-sen | 8/23/99-8/30/99</Title> <Url>http://www.time.com/time/asia/asia/magazine/1999/990823/sun_yat_sen1.html</Url> <ClickUrl>http://www.time.com/time/asia/asia/magazine/1999/990823/sun_yat_sen1.html</ClickUrl> </Result> <Result> <Title>Money Magazine Subscription Offer</Title> <Url>http://subs.timeinc.net/CampaignHandler/MOnb?source_id=16</Url> <ClickUrl>http://subs.timeinc.net/CampaignHandler/MOnb?source_id=16</ClickUrl> </Result> <Result> <Title>Investor's Guide - Middletown Thrall Library</Title> <Url>http://www.thrall.org/invest</Url> <ClickUrl>http://www.thrall.org/invest</ClickUrl> </Result> <Result> <Title>Turner Broadcasting System - Wikipedia, the free encyclopedia</Title> <Url>http://en.wikipedia.org/wiki/Turner_Broadcasting_System</Url> <ClickUrl>http://en.wikipedia.org/wiki/Turner_Broadcasting_System</ClickUrl> </Result> <Result> <Title>Alfalfa Electric Cooperative - Cherokee, OK</Title> <Url>http://www.alfalfaelectric.coop/</Url> <ClickUrl>http://www.alfalfaelectric.coop/</ClickUrl> </Result> <Result> <Title>PrescottYellowPages.com</Title> <Url>http://prescottyellowpages.com/</Url> <ClickUrl>http://prescottyellowpages.com/</ClickUrl> </Result> <Result> <Title>The Big Picture | Lender-Abandoned, Non-REO Foreclosures</Title> <Url>http://bigpicture.typepad.com/comments/2008/04/the-advantages.html</Url> <ClickUrl>http://bigpicture.typepad.com/comments/2008/04/the-advantages.html</ClickUrl> </Result> <Result> <Title>Pay off holiday debt in the new year - Holiday Guide - MSNBC.com</Title> <Url>http://www.msnbc.msn.com/id/6531029/</Url> <ClickUrl>http://www.msnbc.msn.com/id/6531029/</ClickUrl> </Result> <Result> <Title>Insurance - Auto Insurance, Home, Health, etc. from CNNMoney.com</Title> <Url>http://money.cnn.com/pf/insurance/</Url> <ClickUrl>http://money.cnn.com/pf/insurance/</ClickUrl> </Result> <Result> <Title>TIMEasia.com | TIME 100: Emperor Hirohito | 8/23/99-8/30/99</Title> <Url>http://www.time.com/time/asia/asia/magazine/1999/990823/hirohito1.html</Url> <ClickUrl>http://www.time.com/time/asia/asia/magazine/1999/990823/hirohito1.html</ClickUrl> </Result> <Result> <Title>The Big Picture | Why is Movie Theatre Revenue Attendance Declining?</Title> <Url>http://bigpicture.typepad.com/comments/2005/07/declining_movie.html</Url> <ClickUrl>http://bigpicture.typepad.com/comments/2005/07/declining_movie.html</ClickUrl> </Result> <Result> <Title>Home Page</Title> <Url>http://www.personal.psu.edu/faculty/j/x/jxz8/Student_Webquests/Neu_Sel_Yar/Questts/Ourquest</Url> <ClickUrl>http://www.personal.psu.edu/faculty/j/x/jxz8/Student_Webquests/Neu_Sel_Yar/Questts/Ourquest</ClickUrl> </Result> <Result> <Title>Papal Succession Primer</Title> <Url>http://www.time.com/time/daily/special/papacy/how.html</Url> <ClickUrl>http://www.time.com/time/daily/special/papacy/how.html</ClickUrl> </Result> <Result> <Title>TIMEasia.com | TIME 100: Pol Pot | 8/23/99-8/30/99</Title> <Url>http://www.time.com/time/asia/asia/magazine/1999/990823/pol_pot1.html</Url> <ClickUrl>http://www.time.com/time/asia/asia/magazine/1999/990823/pol_pot1.html</ClickUrl> </Result> <Result> <Title>It's spring: Time for a little exercise - Mar. 15, 2004</Title> <Url>http://money.cnn.com/2004/03/12/commentary/everyday/sahadi/</Url> <ClickUrl>http://money.cnn.com/2004/03/12/commentary/everyday/sahadi/</ClickUrl> </Result> <Result> <Title>Taking advantage of lower interest rates - Jun. 27, 2001</Title> <Url>http://money.cnn.com/2001/06/27/home_auto/fed_consumer/</Url> <ClickUrl>http://money.cnn.com/2001/06/27/home_auto/fed_consumer/</ClickUrl> </Result> <Result> <Title>How to get rich in America - Smoothie operators (1) - Money Magazine</Title> <Url>http://money.cnn.com/galleries/2007/moneymag/0706/gallery.success_stories.moneymag/index.html</Url> <ClickUrl>http://money.cnn.com/galleries/2007/moneymag/0706/gallery.success_stories.moneymag/index.html</ClickUrl> </Result> <Result> <Title>The Big Picture | The Return of M3</Title> <Url>http://bigpicture.typepad.com/comments/2006/11/the_return_of_m.html</Url> <ClickUrl>http://bigpicture.typepad.com/comments/2006/11/the_return_of_m.html</ClickUrl> </Result> <Result> <Title>TIMEasia.com</Title> <Url>http://www.time.com/time/asia/asia/magazine/1999/990719/souls1.html</Url> <ClickUrl>http://www.time.com/time/asia/asia/magazine/1999/990719/souls1.html</ClickUrl> </Result> <Result> <Title>The Big Picture | How SubPrime Really Works</Title> <Url>http://bigpicture.typepad.com/comments/2008/02/how-subprime-re.html</Url> <ClickUrl>http://bigpicture.typepad.com/comments/2008/02/how-subprime-re.html</ClickUrl> </Result> <Result> <Title>Consumer World: Money, Credit and Investing</Title> <Url>http://www.consumerworld.org/pages/money.htm</Url> <ClickUrl>http://www.consumerworld.org/pages/money.htm</ClickUrl> </Result> <Result> <Title>welcome-to-china.com, Best web sites Resources, Top 100 Sites, Top web ...</Title> <Url>http://www.welcome-to-china.com/</Url> <ClickUrl>http://www.welcome-to-china.com/</ClickUrl> </Result> <Result> <Title>The Big Picture | We've gone Map Crazy!</Title> <Url>http://bigpicture.typepad.com/comments/2004/11/weve_gone_map_c.html</Url> <ClickUrl>http://bigpicture.typepad.com/comments/2004/11/weve_gone_map_c.html</ClickUrl> </Result> </ResultSet> <!-- fe03.sitex.search.sk1.yahoo.com uncompressed/chunked Thu Oct 9 01:31:06 PDT 2008 --> <!-- ws04.search.scd.yahoo.com uncompressed Thu Oct 9 01:31:06 PDT 2008 --> Do you have any idea why? it seems so simple on the surface but it's absolutely rediculous how I can't do this with a simple preg_match or substr. Any other advice is welcomed. Thanks.
  10. I have no idea how I should be doing this and I am in desperate need of help. I have an xml file. At the beginning is this: <ResultSet xsi:schemaLocation="urn:yahoo:srch http://api.search.yahoo.com/SiteExplorerService/V1/InlinkDataResponse.xsd" totalResultsAvailable="547535" firstResultPosition="1" totalResultsReturned="50"> How do I simply put 'totalResultsAvailable' (547535) into a variable? I have tried using substr and have successfully singled out the number but it is forever trapped between two double quotes. Any help on this is greatly appreciated.
  11. That is exactly what I was looking for. Thank you very much!
  12. Hi guys. I've just been looking into Geshi and how it functions..it's way too complicated for me right now but I have a question. Is there a simple way I can target every instance of a word in a string and style it? Any input much appreciated. Thanks.
  13. Thanks discomatt! __FILE__ works perfectly. I'm running it on a local machine so not sure how that will effect the second method. I'll give the other method a try if I decide to put this online. Thanks again!
  14. Is there a command for obtaining the name of the script being run..obviously a command I would have to run in the script? Can I do this: $thisfile = ///// command I want file_get_contents($thisfile); Basically I want to run my test scripts but also feature the actual code on the same page. Thanks for any help.
  15. Maybe try to separate the calculation. Retrieve the previous number, add 1 and reinsert. $num = $fetch['votes'] +1; ///of course, $fetch will have to be created then.. SET votes = $num WHERE..etc not ideal, but should work. Very strange.
  16. Hi guys! I have created a function for cleaning user input. $var1 = "what now?"; $var2 = "whatever.."; $no1 = "/\./"; $no2 = "/\?/"; function clean_field($field, $illegals){ $field1 = mysql_real_escape_string($field); if($field1 == "False" || preg_match($illegals, $field1)){$field2 = "Bad";} else {$field2 = $field1;} return $field2; } clean_field($var1, $no1); clean_field($var2, $no1); Where the return is, I can echo the variable and I can see the function is working fine. What I want to do though is output the 'clean' var into a new var. Is it possible? to clarify. I want to take $var1 ---> put it through the function ---> create a new var. Really appreciate any help with this. Thanks.
  17. Sorry to bump this, but...really?? How does no one know what I'm talking about? I want to produce a possibility using the three 'weight' variables. To clarify. I have assigned a weight to each of the variables, name1, name2, and name3, ..those weights are 25, 25, 50, respectively. Now how do I make my script: -call name1 25% of the time -call name2 25% of the time -call name3 50% of the time I can't find any info on this.. I'm beginning to think it can't be done. I would appreciate someone to tell me so than take the piss. In that case <?php $name1 = "Damien"; $name2 = "Liam"; $name3 = "Deiter"; $n1weight = "25"; $n2weight = "25"; $n3weight = "50"; for ($i=1; $i<=3; $i++) { $n = ${'name'.$i}; $w = ${'n'.$i.'weight'}; echo "$n : $w<br/>"; } ?> But wait, how about: echo "Damien: 20 Liam: 20 Deiter: 50"; ??
  18. again, I'm sorry if I'm not being specific enough. The output I receive from the script I wrote is: Damien: 22 Liam: 27 Deiter: 51 And those figures vary each time the script is run (5 or so for each line, give or take). What I want is: Damien: 20 Liam: 20 Deiter: 50 ...Every time. Ignore my comments about reliability. Have you got any suggestions? many thanks for your time.
  19. From what I remember it isn't your code or the database settings...it's what you are using to view the output. Try using a defining different encodings. example: <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> Here's a helpful tutorial: http://www.w3.org/TR/REC-html40/charset.html Hope that helps.
  20. ok. So first thing: get over yourself! Don't expect everybody to drop to their knees for you. Second, being at least a capable designer, you should know that 80% of email clients will process html just fine. One thing about php...it's server based. You don't use an email client to send emails with it. Email clients do not need to process the php because the php is processed first. You will have to use a little something called phpmailer...or create a simple mail(); function. That's when this comes into play: "make a database of random sayings and select the saying from a random number that's the idx for that record." ...hope that helps.
  21. Would you care to define jut what that means? Remember that random is random. Sorry, what I mean is that the percentages I am generating are unreliable. Have you any suggestions? Thanks.
  22. Just to clarify. I'm looking for the best way in which to perform and action (call a variable) determined by an exact percentage. I did do a little rand(); test and came up with this. $name1 = "Damien"; $name2 = "Liam"; $name3 = "Deiter"; $n1weight = "25"; $n2weight = "25"; $n3weight = "50"; $n2diff = $n1weight + $n2weight; $n3diff = $n2diff + $n3weight; $num = rand(1, 100); echo "<br><b>Percent Test</b><br>"; $loop=1; $n1num=0;$n2num=0;$n3num=0; while($loop <= 100){ $num = rand(1, 100); if($num <= $n1weight) {$n1num++;} if($num > $n1weight && $num <= $n2diff) {$n2num++;} if($num > $n2diff && $num <= $n3diff) {$n3num++;} $loop++; } echo "Percents:<br> $name1: $n1num"."%"."<br>". "$name2: $n2num"."%"."<br>". "$name3: $n3num"."%"."<br>"; $totalnum = $n1num + $n2num + $n3num; echo "<b>Total: $totalnum</b>"; The amount of times a particular name is called varies around 2-6 give or take. Obviously it always add up to a hundred, but the figures are unreliable. Ignore experimental syntax..I'm still learning :-) Is there a more reliable way of doing this? Thanks.
  23. Hey guys, thanks for the all the input. Here's what I've gone with: foreach(glob("links/(*)link.*") as $linkfile){ $links["$loop2"] = $linkfile; echo "Link File:$linkfile<br>"; $loop2++; }$loop2 = $loop2 -1; shuffle($links); echo "<br><b>Chosen Links:</b><br>$links[1]<br>$links[2]"; So I've kept the original array I had and simply shuffled it, yet used the same numbers. I hope is isn't deprecated anytime soom..eek. Much appreciate all of the advice and info. Bookmarked this so I can come back should I need to extend my script. Thanks again!
  24. I've actually run into another little niggle. Is it possible to put the two random links into an array? (I'm using Gingers code). So I have: randomlinks($links, 2); But how do I put the two that were chosen into their own array? Thanks for the extension matt, I'll try that.
×
×
  • 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.