The posttextarea graphic information is sent to the background, but the background cannot be extracted to the image array ???? -Php Tutorial

Source: Internet
Author: User
The posttextarea graphic information is sent to the background, but the background cannot be extracted to the image array ???? Post extract image http

I used kindeditor to create a textarea online editing box. when a user deletes an image in textarea and uploads another image, the server space is saved .. I extracted the textarea image from the original database to form an array, and then compared each value in the array with the new textarea in_array (). The unsaved image will be deleted .. It is strange that the newly passed textarea cannot be extracted to the image array, and the extraction result is an empty array .. Thank you for your consideration ..


Reply to discussion (solution)

When you delete an image in textarea
How can you extract the image address from the new textarea?

.. At this time, the image array extracted from the original database textarea is relative to the image array received in the background. The Missing image path is the image that the user deleted on the foreground but not deleted on the server ..
When you delete an image in textarea
How can you extract the image address from the new textarea?

The problem is that in any case, the image array extracted from $ _ POST ['textarea '] received from the background is empty .. But $ _ POST ['textea '] does contain img images .. The strange thing is that it is correct to save the data to the database for extraction. it can only be obtained as null if it is extracted directly from $ _ POST ['textta ..
When you delete an image in textarea
How can you extract the image address from the new textarea?

You need to know how you extract
You also need to know the content of $ _ POST ['textarea '].

Content in foreground textarea:


Aiweitao is a professional technical team engaged in mobile application development and api development.


Backend receiving and processing:
$ Content = isset ($ _ POST ['content'])? $ _ POST ['content']: false; $ pic_now = get_pic_html ($ content); // The current image array print_r ($ pic_now ); // always empty/** extract images from html and integrate them into an array @ param string $ str @ return array */function get_pic_html ($ str) {$ pattern = "/<[img | IMG]. *? Src = [\ '| \ "] (. *? (? : [\. Gif | \. png | \. jpg]) [\ '| \ "]. *? [\/]?> /"; // Regular expression preg_match_all ($ pattern, $ str, $ match); return $ match [1]; // return a one-dimensional array with only the image path}

You need to know how you extract
You also need to know the content of $ _ POST ['textarea '].

$ S = <HTML


Aiweitao is a professional technical team engaged in mobile application development and api development.

HTML; function get_pic_html ($ str) {$ pattern = "/<[img | IMG]. *? Src = [\ '| \ "] (. *? (? : [\. Gif | \. png | \. jpg]) [\ '| \ "]. *? [\/]?> /"; // Regular expression preg_match_all ($ pattern, $ str, $ match); return $ match [1]; // returns a one-dimensional array with only Image paths} print_r (get_pic_html ($ s ));
Array
(
[0] =>/info/201311/1384551494771680415 .jpg
)
Your code has no major problems.

However, you still need to verify the result of echo base64_encode ($ _ POST ['textarea ']);

Directly printed on the background, php automatically escaped the img p span and other tags with double quotation marks after the post ..
Therefore, the image tag becomes invalid due to regular expression verification ..
Perform stripslashes () on the post data to remove the backslash and then click OK ..
It is strange that the textarea written into the database does not have a backslash ..

$ S = <HTML


Aiweitao is a professional technical team engaged in mobile application development and api development.

HTML; function get_pic_html ($ str) {$ pattern = "/<[img | IMG]. *? Src = [\ '| \ "] (. *? (? : [\. Gif | \. png | \. jpg]) [\ '| \ "]. *? [\/]?> /"; // Regular expression preg_match_all ($ pattern, $ str, $ match); return $ match [1]; // returns a one-dimensional array with only Image paths} print_r (get_pic_html ($ s ));
Array
(
[0] =>/info/201311/1384551494771680415 .jpg
)
Your code has no major problems.

However, you still need to verify the result of echo base64_encode ($ _ POST ['textarea ']);

The escape character is saved to the database for convenience. it is not retained by the database.

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.