Jump to content

ghostdog74

Members
  • Posts

    84
  • Joined

  • Last visited

    Never

Everything posted by ghostdog74

  1. i don't understand what you mean by "no matter where it is", but anyhow, here's something non regex , $str = "f=varying-string&killer=lop&you=pop"; $s = explode("&",$str); $tmp=$s[0]; $s[0]=$s[1]; $s[1]=$tmp; print implode("&",$s);
  2. i have not specifically harded any image file type. as you can see, my code searches for "img class" , therefore, if the link is to a png file, it should still grab for you
  3. no need regex. simple split will do $string = "success adding the records in the river table by scvinodkumar today at 6.36 pm by scvinodkumar [[Category:Test]]"; $s = explode("[[Category:Test]]",$string); print $s[0];
  4. $string = '1051 JoZlkA11215'; $s = preg_replace("/[^a-zA-Z]+/","",$string); print $s;
  5. just use normal string functions $url = "http://profile.myspace.com/index.cfm?fuseaction=user.viewProfile&friendID=6221"; $page = strip_tags(file_get_contents($url),"<img>"); $p = explode("/>",$page); foreach($p as $k=>$v){ if(strpos($v,"img class=")!==FALSE) { $jpg = explode("src=",$v); $imagelink = preg_replace("/\"/","",$jpg[1]); #remove doublequotes print "imaglink " . $imagelink; $image = file_get_contents($imagelink); $f=fopen("friend.jpg","w"); fwrite($f,$image); fclose($f); } }
  6. $fp = "[Querying whois.arin.net] [Redirected to whois.ripe.net:43] [Querying whois.ripe.net]"; $a = preg_split("/Querying/",$fp); print end($a);
  7. i only looked at his first post. if its not what he wants, then so be it.
  8. $message="my name is @ redarrow"; if ( ctype_alnum ($message) ){ print "$message is alphanumeric\n"; }else{ print "'$message' is not alphanumeric\n"; }
  9. you do not need to start a mail service if all you are doing is sending out mails.
  10. i would advise against using external shell tools like that as it makes your code not portable. whenever and wherever you can, always try to use PHP's mail methods/classes. Here it has example of how to send html email. I am also sure that if you search hard enough you can find lots of examples on the net.
  11. you are about there. but that says match 2 spaces. if there are 2 or more spaces, you can use {2,}
  12. good. the bottom line is, PHP provides you numerous string functions you can use, regex should be the last thing that comes to your mind.
  13. have you read the manual? see ftp_rawlist() function.
  14. replace the newline with space. $a = preg_replace("/\n/"," ",$find); then continue your checking.
  15. how about this, no regex $docName="Ap%praisal Agreement"; $a = explode(" ",$docName); if ( count($a) == 2){ print "ok, space in between\n"; } if ( ctype_alnum ($a[0]) ){ print "$a[0] is alphanumeric\n"; }else{ print "$a[0] is not alphanumeric\n"; } if ( ctype_alnum ($a[1]) ){ print "$a[1] is alphanumeric\n"; }else{ print "$a[1] is not alphanumeric\n"; }
  16. yes, that's right. if you don't need arrays, then after exploding on the "&", the array will contain 3 elements. that's all you need. if you don't understand what its doing in the first place, then don't use it. regular expressions , although powerful, tends to make things look "gibberish". Even worse if you are not well trained in regex. Being more expressive in your codes will make your life easier next time, both in the area of maintenance and code troubleshooting.
  17. $string="height=6&weight=170&eyes=brown"; $s = explode("&",$string); foreach( $s as $k=>$v){ $v=explode("=",$v); $a[$v[0]]=$v[1]; } print_r($a);
  18. ok , so you are listing files from inside an FTP session? PHP has almost any kind of libraries you need to make life easy for you. check out the FTP module. you can use ftp_nlist() function to list files from remote server, then get the results and manipulate them as you wish.
  19. why don't you use PHP readdir() and fileperms() ?? some things you just have to keep simple.
  20. Just split the string and put a limit on the split. $string = "Date: Wed, 24 Dec 2008 01:52:41 GMT"; $a = split(" ",$string,2); print "What i want is $a[1]\n";
  21. $string = '{hyperlink|ahref|text}'; if ( substr_count($string,"|") > 1 ) { echo "yes, more than 1\n"; }
  22. when parsing XML/HTML, its better to use dedicated classes/methods (if you have them) than constructing regex from scratch. $string = '<a name="poster" href="/rg/action-box-title/primary-photo/media/rm118396416/tt0811080" title="Speed Racer"><img border="0" alt="Speed Racer" title="Speed Racer" src="http://ia.media-imdb.com/images/M/MV5BMTA5MjgxMDE4OTVeQTJeQWpwZ15BbWU3MDgyNjc4NjE@._V1._SX94_SY140_.jpg" /></a>'; if ( ($start = strpos($string,'<a name="poster"' ) ) !==FALSE ) { $xml = new SimpleXMLElement($string); echo $xml->img['src']; }
  23. i am providing another way to solve that issue without messy regexp. What's wrong with that?
  24. split the string on space, go through each word and find "(" and ")". $string = 'function LoadGif($imgname)'; $s = explode(" ",$string); foreach ($s as $k=>$v){ if ( strpos($v,"(") !== FALSE && strpos($v,")") !==FALSE){ echo "Found : $v\n"; } }
×
×
  • 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.