PHP micro-Credit Public Development notes (vii)

Source: Internet
Author: User
Tags foreach format array arrays count functions mysql tidy
PHP micro-Credit Public Development Notes series
Date: 2014.9.6

This diary is mended yesterday, yesterday did not have time to write;

Main functions: fuzzy retrieval, question answering system, help system
Fixed: ID of _session
Tuning the validation mechanism

To note: MySQL syntax problems, MySQL fuzzy matching, php associative array as if using count of the size of the original data is twice times larger (that is, the array of only two data, Count will get 4, this need to be validated, It seems to be the problem with foreach.

Learned: The operation of arrays in PHP

2014.9.10 to organize notes:
Write this note, in the rush function, so that is simply a few strokes of the work of the time, now the function developed almost, just to tidy up the previous notes. It was very simple to record the above sentences.
I remember, on the way to work that day, my classmate said to me, I hope the function is: Enter the name of a city, you can  of the students in this city. Actually this function is I originally want to get this micro-letter public number want to achieve the function, so it can be very convenient for information retrieval, although at this stage we may not have a lot of people walking around, there is no demand. But there is no chance, so there is this idea.

Fuzzy Search:
Fuzzy search words, is also based on database retrieval, here should be a keyword, so that the Help desk program can capture this keyword, I set to view the +XX to view information, such as to see the information in Guangzhou, then reply to "see Guangzhou" can be.
Specific implementation:
The first is the keyword capture, which is similar to note six, which is just a two string processing function: Strstr,str_replace processing user input information, the key is how to deal with the information from the database, the beginning of my idea is whether the database can do fuzzy search, If it is not possible to get all the information first, then to contrast;
scenario One, about fuzzy matching of databases:
Information from the Internet to show that the support of fuzzy search, but I tried for several hours, is no effect, I do not know is not my understanding of this fuzzy search error, the online look at the syntax is:
1,Select from XXX (datasheet name) where xxx (field) like XXX (we want to retrieve), the user gives the introduction is that this syntax can be from the given data table, retrieve the corresponding field value for the information we want to find. But what we want to do here is the multi-field view, namely the data table has the province, the city and so on field information, I need to do these fields the fuzzy match, therefore began to consult the material again;
2,Select from xxx where concat ("field_a", "Field_b", "Field_c") like XXX, where concat is equivalent to combining more than one field, and then to do a fuzzy match, I followed this, but still did not succeed;
3,Select from xxx where xxx.colum_name like XXX, which is also a reference to the data, is changed by the field name changed to: Datasheet. Colum_name this to match, but still no use;
The specific is not used according to my printed information is, using mysql_query to retrieve the information, but this result with MYSQL_FETCH_ASSOC or mysql_fetch_array processing, and did not get the corresponding array, do not know what the situation Here also note that: like the next fuzzy matching information, according to the views provided by netizens, if the Chinese characters need to be written as% to retrieve the format, that is, both sides must have a percent.
Although here said did not meet my needs, but still feel, to be able to very good operation of the database, then need to take a good look at the MySQL operating manual.

This plan should be said to be very simple and easy to do, because I do in the hands of the project is so handled, in fact, I began to have a vague search this demand, but also think of this method. But I thought that getting the information from the database first required access to the database search, and then the comparison took time, which might affect performance, so I figured out whether there was a solution on the Internet. But it backfired, did not meet the expected needs, this will be left to see later.


The solution is simple, just start by getting all the information and then compare it. Here we use an operation function of the PHP array to make the contrast very simple: In_array (), or whether a value is in an array. Because we  from the database, PHP is processed into an array, I search the word guangzhou, I just need to determine whether the word in these arrays in Guangzhou is OK, so relatively simple. The concrete realization I did this:


vcv509c1xndfz6kjrmi7uvprrbu31ek49rb+zqzk/ Dfpo6zdv7to0a27t7xdtb3su7j2yv3x6ddfz6kjrmi7uvpipbj6ztldx9kqvozl97xejimymdu0mdvipbbuscijrmalxes1vchlvs29q9xiupbk /dfpt8w1vc7sw8e1xl3hufvk/dfp1tdipaosylu689tauvpd5rxestnx99bq1/a94bn7tkba7b7nv8ns1mhloam8yni+ctlytmu52npaxko6/ bzsy/fv4rj2uabe3lxjvs3v4th5yrxp1shloam8yni+cjxicj4kphn0cm9uzz7oyrtwz7xns6o6pc9zdhjvbmc+ pgjypgru2rm5y7zeo7r9vozl97xeyrg68qosztlsss/ro6zkx7fxxnzfqrj2uabe3mc0so/w+ s2s0ae72nlku9js5ltz0ae1xlarzveho9pqwcvv4rj2z+u3qnauuvojrm7subnlvmhl0ru49r3q1/ boyrtwtcs5pstco6y8tnpdu6e72li0zsq08kosz7xns77nt7w72nk7upboysziymptw7unykw72ltwoapv4tcpzsrm4ra8yse52npatpprp8n6u +61xkosyofrp7rf1q7a4lxeoam8yni+ctpqwcvv4rj2z+u3qnauuvojrlhjv6rkvnffytbktc/wwcujrnlyzqro0s/ rtb278tdt0ts689xiupa5pstcu+ht0mcp1bmjrmv50tto0tlu0ru49sdgwltktc/wo6zo0rpg1q7oqs7s1ek49s+1zbo1xnk7upbeo7/ po6yx49pazbpsu7ncwo2hozxicj4kvt/ m5bxeyrxp1rrcvpk1paosvs3kx9ta08o7p7vyulshsm7ktpchsbxeyrg68qos08mkx1nfu1njt068x8k80rvpwtpdu6e/qsb0wcvoyrtwxko/ 6aosylu689pdu6e1xm/c0ruyvbvyultqxc+ivs3kx7vytpde2sjdwcujrlvytpcyu7ncs8m5psqnsny2vmfls/219crfu0vtu0lptrny09rtw7unv6rg9m7ktpdeo7/ptctqxc+ioao40l711elr+ cq1z9a1w9pqteo88rwltnaxqaosuf65/qgjpgjypgq+38zlyrxp1rrcvpk1paosvli69co709df9rw9uty087xezsrm4qosy/ns1lk7zog+ 38zlyrxp1shloam8yni+cjxicj4kphn0cm9uzz6w79b6z7xns6o6pc9zdhjvbmc+pgjypgo8cd6w79b6z7xns87stcs5uc/ Rysejrmzhuann5txiupa5q9bausw1xl3ms8yjrlywvpk1pbxeupzqwsjv1r65pstcoapp67w90qrfqtxiw7s24kosxmfdtntzu9i4tm7esb7qxc +iv8+2ql7nsrvmq7rdwcujrmv50ts+zddo0qq72li0zbzoxmg0vdpby6gjzbzoxmg0vdo1xlvyultu2rnzt721xl+qt6loxlw11tc+zdpqvt/ m5bxey7xd98hlo6zo0r+0tb3n+nprtcs3vbeoo6y9q8th0ru087sueg1stk631r3iv6ratlsmwo2jrm7s0rk4+ Tff1eldtnf2wcujujwvcd4kpha+pgltzybzcmm9 "/program/uploadpic/2014-9/201492512821762.png" alt= "\" >


Pass over an array, and then do processing, you can easily reply to the text link.
Here to mention the click on the link after the jump:
Because I don't know what to do with that link (no concept at all), and then think it should be a file, the link is the address of the file. Then I just use PHP to write a file, put it in the SAE storage, put this link, test the effect is like this.
Often browsing the web, and see the Web page is more HTML, so you want to how to generate HTML files, online search data HTML file How to generate, but also online generation of web pages, but also word save for HTML, and then go home with Dreamweaver. Later, the HTML file is generated, but there is no good matching mobile phone browsing needs, it should be said that is not at all like a Web page, maybe I have a little bit of web design basis should be able to, the web has a lot of template material.
Later, I did not intend to be in the public platform of the material library to see my classmates to do some of the documents, I thought, can I use the help of the document is also used to deal with the material, directly create a new material, the contents of the Help document is the information. Let's go and add the Help document that's written directly to my newly created footage and save the test results. The result is very satisfied, is the effect that I want, this is just like the webpage that the handset opens. Because of a bit of obsessive-compulsive disorder, always to adjust the format of what, so busy to fast 12 o'clock that day to tidy up, that day is Friday, back to rent the house is almost the night eight o'clock, back after a little tidy up is in the public platform, and then busy to 12 o'clock around. Although tired, but very happy.

PHP Note points:

SESSION_ID () Use this function to set the ID
Because the message received by the micro-credit public number, there is a message that is sent to the user, you can use this ID to make the value unique, so I was the user's information to set the ID, but then there was a problem. I initially thought it was the problem with this mechanism and thought I was using it improperly. So the call order of the functions is adjusted:
was supposed to be
session_id ();
Session_Start ();
This call order, I think is not this sequence is not right, I changed, the result is still wrong. Later, I seriously looked at the setting of this ID, only to find that I wrote the user information is wrong, the case is not clear, really careless killing people.
The user information obtained from the micro-trust server is as follows:
$POSTOBJ->fromusername
And I used it $postObj->fromusername.
And I never found out ... Eh .....
2, the PHP array:
With associative arrays, if you use foreach to do a loop, the number of loops will be twice times the size of its count. This is the problem that I ran into when I did the fuzzy search. At that time I did not use In_array to do the match, but use the loop array to do the matching, the information found on the Internet is that the associative array to match using foreach, so you can also get the key value:
foreach ($array as $key => $value) 
{
       if ($array [$key] = xxx)
       $res _array[] = $array [$key];
}
When I did this, the number of times this cycle was twice times the size of the group, I printed the key, showing that both the associated key was printed and the value key was printed. That is, the first print is a numeric key, the second print corresponding associated key, the same element will be printed two times. So when I do a match, I get two of the same array. I don't know if it was a problem where I used it.

Related Article

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.