Jump to content

ghostdog74

Members
  • Posts

    84
  • Joined

  • Last visited

    Never

Posts 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. 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);
        }
    }
    

  3. advance thank you.

     

    how the hell it letting the @ in, when only a-z 0-9 are allowed only.

     

    madness

     

    <?php
    
    $message="my name is @ redarrow";
    
    $err="Sorry you have not filled in the form correctly!";
    
    if(!preg_match("/[a-z0-9]/i",$message)){
    
        echo $err;
       
    }elseif(empty($message)){
    
    echo $err;
    
    }else{
    
    echo $message;
    }
    
    ?>
    

     

    $message="my name is @ redarrow";
    if ( ctype_alnum ($message) ){
    print "$message is alphanumeric\n";
    }else{
    print "'$message' is not alphanumeric\n";
    }
    
    

  4. Now there is a tool named nail which can also send mail without using the sendmail so my code looks like this as a sample

     

    <?php

    $message="Hi test";

     

    system('cat $message | /usr/local/bin/nail -r monsrv@abc.com -s "Test Mail with Nail" tanveer@abc.com')

     

    ?>

    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.

  5. 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";
    }
    
    

  6. ghostdog74, it seems like your script will return an array rather than distinct variables holding strings.  Is that right?

    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.

    What do you think of this one?  I got it from another source but it looks like gibberish to me (seems to work though)

    $querystring = 'height=6&weight=170&eyes=brown';
    preg_match_all("/(.*?)=(.*?)(&|$)/", $querystring, $matches);
    for ($i = 0; $i < count($matches[0]); $i++) $$matches[1][$i] = $matches[2][$i];

    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.

  7. ghostdog74,

    The reason why I can't use those is that this information comes from a FTP connection (via a socket). I didn't see any information in FTP functions on getting the file permissions.

    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.

  8. Now, I just want a regex to remove "Date:" and just display

    Wed, 24 Dec 2008 01:52:41 GMT

     

    How come above is not working?

     

    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";
    

  9. Hello.

    I'm trying to extract the image src value.

     

    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'];
    }
    
    

  10. Unsolved this because I discovered an issue

     

    It's matching the entire string, for example

     

    function LoadGif($imgname)  
    

     

    Only LoadGif($imgname) should be found and made bold, however it's also pulling in everything to the left of that too

     

    Any ideas on how to make it not go back like that?

     

     

    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.