Jump to content

Recommended Posts

rhodesa:

 

$text = "Your file '357968007770859.ask' has been calculated.";

$matches = "ask";

 

if(preg_match('/[^ ](.+?\.ask)/',$text,$matches)){

  $filename = $matches[1];

  echo $filename;

}

 

Output: our file '357968007770859.ask

 

Text in color shouldn't appear. I like it, Would u please fix it

 

stephan:

sorry, i am very biginner, I didn't understand where the text that will look in?

would u please explain more.

 

thanks again

actually i am not sure if it is always begings with Zero.

I think you mean the code finds numbers between 0-9 (which are the file name) but didn't know where's the text variable that going to look for.

 

the preg_match is easier for me if fixed. please

 

 

would something like this work:

<?php
$data = "this is an example of searching for 357968007770859.ask";
$data_array = explode(" ", $data);
foreach ($data_array as $value){
if (strstr($value, ".ask")){
	$result[] = $value;
}
}
print_r($result);
?>

this will give you any instances of *.ask, in array form (so if you have more than one per search, it will pull up all)

I would use preg_match, but I suck at it.

Hi copied ur code as is, this was the output:

Array ( [0] => 357968007770859.ask )

 

it is not exactly as i need it, i need to save this file name to make a check for it in a DB table.

please note that i will always have only ONE name in this sentence.

Could you please modfiy the code.

thanks for your patience

<?php
$data = "this is an example of searching for 357968007770859.ask";
$data_array = explode(" ", $data);
foreach ($data_array as $value){
if (strstr($value, ".ask")){
	$result = $value;
}
}
?>

your data that you need is saved in the variable $result. run your query using that variable.

Your Code works 100% correctly. still small issue

 

the text that will be searched is always in this format:

 

Your file '357968007770859.ask' has been calculated.

 

Notice that single quotation before and after the file name, when I used this sentnece in your code the output file name was:

'357968007770859.ask'

I need to remove the single quotations from begining and the end of the file name, please.

thanks

Hi

 

$text = "Your file '357968007770859.ask' has been calculated.";

$matches = "ask";

 

Actaully I prefer your short codes but your last preg_match gave me this output:

 

9.ask

whiel ti should be: 357968007770859.ask without any single quotation on both sides

 

 

thanks again

Hello

 

I always have one of the following sentences format.

 

Error processing your order for ASK file: 358952017459231.ASK.ask!

OR

Error processing your order for ASK file: 358952017459231.ask!

 

I need to store the .ask name in a variable. there's always an ! mark at the end!

 

e.g: First String    = 358952017459231.ASK.ask

      Second String =  358952017459231.ask

 

If an error occured i will always receive one of the above error messages, but the user in the first one include .ASK in the file name as you know.

 

Kindly help and thanks in advance.

  • 2 weeks later...

Hello

 

i am using now this preg_match and it working perfect. It is always applied on this sentence:

$subject = Your file '357968007770859.ask' has been calculated

 

<?php
preg_match('/\S+\.ask(?=!)/i', $subject, $matches);
  	$filename = $matches[0];
?>

 

I just noticed that the above $sbject might be:

Your file '_357968007770859.ask' has been calculated.

the code couldn't catch the file name with an underscore in it

 

Would you please give me another preg to look for the ask file name if it begins with _ ?

 

Thank you

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.