Jump to content

afrojojo

Members
  • Posts

    35
  • Joined

  • Last visited

    Never

Everything posted by afrojojo

  1. Hello masters of the regex. I would like your help. I need an expression that would extract the version out of this string. Everything between the last "-" and ".". INPUT: database_name-10182011946-v1.0.2.sql OUTPUT: v1.0.2 Any ideas?
  2. I guess I should update that one.
  3. Try this: if (ereg('[^A-Za-z0-9]', $text)) { echo "This contains characters other than letters and numbers"; } else { echo "This contains only letters and numbers"; }
  4. I think I got it. Adding the ENT_NOQUOTES seemed to do the trick. It was encoding the quotes and messing it up. $string=htmlentities($string,ENT_NOQUOTES); Thanks for all your help. I appreciate it.
  5. I figured out the issue. I applied htmlentities. $string=htmlentities($string); Any way around this? I don't want any other html code displayed.
  6. $string = '<a href="http://yahoo.com">Yahoo</a>'; $pattern = '/((?:https?):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$])/i'; if(preg_match_all($pattern, $string, $match)) { $string=$match[0][0]; echo $string; } Output http://yahoo.com">Yahoo</a>
  7. Oops... /((?:https?):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$])/i
  8. $pattern = '/((?:https):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$])/i'; if(preg_match_all($pattern, $string, $match)) { $string=$match[0][0]; echo $string; } Input: http://yahoo.com this is some text Output http://yahoo.com The above is ok Input <a href="http://yahoo.com">Yahoo</a> Output http://yahoo.com" I want to remove that last quote.
  9. I suppose I should rephrase this. I want it to stop at the first space, the SECOND quote, or the SECOND apostrophe, and begin at http:// or https://
  10. $pattern = '/((?:https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$])/i'; if(preg_match_all($pattern, $string, $match)) { $string=$match[0][0]; echo $string; } I came up with that using preg_match_all. It's almost what I want. $string = "<a href="http://google.com">Google</a> this is some text http://yahoo.com this is some texthttp://msn.com"; If the string was what I have above, how do I make the pattern stop at a " or '. Otherwise the first string produced would be http://google.com">Google</a>. I just want it to be http://google.com. It only stops at the first space. I would like it to stop at the first space, the first ", or the first '. So I would want the output of $string=$match[0][0] to be http://google.com. The output of $string=$match[0][1] to be http://yahoo.com, and so on.
  11. One more question. Is there a way to choose which match in the string it gets? match[1] = The first url in string match[2] = The second url in string
  12. I've searched. I couldn't find anything. Thats not what my question was related to. I tried that. Doesn't work.
  13. That's not what I asked.
  14. Need some help extacting the first url from a string. Whether it would start with http or https. Thanks Input this is some text http://yahoo.com/directory/file.php?id=1&blah=1 this is some texthttp://msn.com this is some text this is some text https://google.com. Output http://yahoo.com/directory/file.php?id=1&blah=1
  15. Example input: ex.1 Some text -- Some other text ex.2 Some text----------Some other text Output wanted: In both examples above, I would like the output to be: Some text
  16. I have this code that I used to remove all image tags from a string. $pattern = '/<img[^>]+>/is'; $body = preg_replace($pattern, '', $body); How would I change the pattern to cut everything out of the string($body) after it sees "--". Would like to cut out the "--" as well.
  17. Yeah, im an idiot. Thanks
  18. #!/usr/local/bin/php <?php // Need PEAR installed include('Mail.php'); include('Mail/mime.php'); require_once 'Mail/mimeDecode.php'; // read email using stdin $fd = fopen("php://stdin", "r"); $email = ""; while (!feof($fd)) { $email .= fread($fd, 1024); } fclose($fd); $params['include_bodies'] = true; $params['decode_bodies'] = true; $params['decode_headers'] = true; $message=new Mail_mimeDecode($email); $mailObj=$message->decode($params); // Who is it from $from=$mailObj->headers['from']; // Get Subject $subj=$mailObj->headers['subject']; // Get Message Body $body=$mailObj->parts[0]->body; $gather="From:$from\nSubject:$subj\nBody:$body"; // Get and Save the Attachments foreach($mailObj->parts as $key=>$val): $tmpObj=$mailObj->parts[$key]; $tmp=$tmpObj->d_parameters['filename']; if(!empty($tmp)): $fd = fopen($tmp, 'w'); fwrite($fd, $tmpObj->body); endif; endforeach; ?> When I send an email with no attachment from a local mail client and echo the $body variable, it shows up empty. The body shows up when there is an attachment though. It also shows up when sent from a webmail app whether there is an attachment or not. What gives?
  19. No, email contains that header string. I'm not sure where $i comes from. echoing $from doesn't show anything. I don't fully understand preg_match, sorry.
  20. What if the header looks like this and is in an $email variable: Header From me@mysite.com Mon Feb 15 11:34:42 2010 Received: from xx-xx-xx-xx.dhcp.eucl-nbb.wi.charter.com ([xx-xx-xx-xx] helo=[xx-xx-xx-xx]) by xx.xx.com with esmtpa (Exim 4.69) (envelope-from ) id 1Nh5mL-00035o-Ti for rsv Code if (preg_match("/^From (\S+)/", $email[$i], $matches)) { $from = $matches[1]; } It doesn't output anything. I want it to output "me@mysite.com".
×
×
  • 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.