PHP search $ keyword result equals to another result at the same time

Source: Internet
Author: User
PHP search $ keyword result equals to another result PHP + mysql. for example, if I want to search for a keyword $ keyword with a value of 25*50, the results of 25*50 and 50*25 are displayed at the same time, then, the search result of 25*50*2.5 is displayed, and the result of 50*25*2.5 is displayed. (25*50*1.1 to 25*50*4.75)
How to judge or use PHP.


Reply to discussion (solution)

Please provide test data

Get submit $ keyword data is 25*50
The result obtained by the following method also shows 50*20. However, if you continue searching for 25*50*2.5, only 25*50*2.5 is displayed, but 50*25*2.5 is not displayed.

$ CArr = array ();
If (! Empty ($ keyword )){
$ CArr ['keyword'] = $ keyword;
}
Require_once ('/config. search. php ');
$ Skeys = array_keys ($ s_replaceArr );
If (@ $ s_replaceArr [$ keyword])
{
$ CArr ['keyword'] = $ s_replaceArr [$ keyword] ['single '];
} Else {
$ Eregpatt = implode ('|', $ skeys );
Preg_match_all ("/^ ($ eregpatt)/", $ keyword, $ res );
// Print_r ($ res );
If ($ res [1]) {
$ KeywordArr = array ();
Foreach ($ s_replaceArr [$ res [1] [0] ['mixed'] as $ svalue)
{
$ KeywordArr [] = preg_replace ("/{$ res [1] [0]}/", $ svalue, $ keyword, 1 );
}

$ CArr ['keyword'] = implode ("", $ keywordArr );
}

}
The config. search. php data is
$ S_replaceArr = Array (
'20 * 40' => array (
'Single '=> '20*40 40*20 ',
'Mixed' => array ('20 * 40', '40*20 ')
),
'40 * 20' => array (
'Single '=> '40*20 20*40 ',
'Mixed' => array ('20 * 40', '40*20 ')
),
'25 * 50' => array (
'Single '=> '25*50 50*25 ',
'Mixed' => array ('25 * 50', '50*25 ')
),
'50 * 25' => array (
'Single '=> '50*25 25*50 ',
'Mixed' => array ('25 * 50', '50*25 ')
)
);
?>
I have many combinations after 25*50. I really don't want to write them one by one to config. search. php. Is there any good solution? thanks to the moderator.

What you may want is this

$ Key = '20*50 * 30'; $ arr = explode ('*', $ key); print_r (Arrangement ($ arr )); // arrange Arrangementfunction Arrangement ($ arr = array (), $ res = '') {if (! Is_array ($ arr) $ arr = str_split ($ arr); if (empty ($ arr) $ array [] = $ res; else foreach ($ arr AS $ k => $ v) {unset ($ arr [$ k]); foreach (Arrangement ($ arr, trim ("$ res * $ v", '*') AS $ t) $ array [] = $ t; $ arr [$ k] = $ v ;} return $ array ;}
Array(    [0] => 20*50*30    [1] => 20*30*50    [2] => 50*30*20    [3] => 50*20*30    [4] => 30*20*50    [5] => 30*50*20)

The moderator writes well.
The last question is how can I accept this array?

$ Arr = Array ("[0]" => "20*50*30", "[1]" => "20*30*50 ", "[2]" => "50*30*20", "[3]" => "50*20*30 ", "[4]" => "30*20*50", "[5]" => "30*50*20 ", "[6]" => "25*50*25"); $ key = "25*50*2.5"; $ arr = explode ('*', $ key ); // print_r (Arrangement ($ arr); // arrange Arrangementfunction Arrangement ($ arr = array (), $ res = '') {if (! Is_array ($ arr) $ arr = str_split ($ arr); if (empty ($ arr) $ array [] = $ res; else foreach ($ arr AS $ k => $ v) {unset ($ arr [$ k]); foreach (Arrangement ($ arr, trim ("$ res * $ v", '*') AS $ t) $ array [] = $ t; $ arr [$ k] = $ v ;} return $ array ;}

Array ([0] => 25*50*2.5 [1] => 25*2.5*50 [2] => 50*2.5*25 [3] => 50*25*2.5 [4] => 2.5*25*50 [5] => 2.5*50*25) to: $ cArr ['keyword'] = 25*50*2.5 25*2.5*50 50*2.5*25 50*25*2.5 2.5*25*50 2.5*50*50*25;

Thanks again to the moderator

The moderator is the moderator!

$ Key = $ keyword; $ arr = explode ('*', $ key); // print_r (Arrangement ($ arr )); // arrange Arrangementfunction Arrangement ($ arr = array (), $ res = '') {if (! Is_array ($ arr) $ arr = str_split ($ arr); if (empty ($ arr) $ array [] = $ res; else foreach ($ arr AS $ k => $ v) {unset ($ arr [$ k]); foreach (Arrangement ($ arr, trim ("$ res * $ v", '*') AS $ t) $ array [] = $ t; $ arr [$ k] = $ v ;} return $ array;} $ aarray = Arrangement ($ arr); $ cArr ['keyword'] = implode ("", $ aarray); echo $ cArr ['keyword'];

Finally succeeded. Thanks again to the moderator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.