Gets the first image address in the text that fits the size

Source: Internet
Author: User
Can preg_match_all get all the image address, loop judgment until find the picture to solve the requirements!

But I want to find the first picture when immediately judge, do not conform to find the second one to judge, how to solve the comparative efficiency? Or is there no problem with all the matching loops?


Reply to discussion (solution)

See

Preg_match

See

Preg_match



Preg_match can only get the first picture address, but how to get the second picture if the picture doesn't fit the size?

Preg_match is it possible to use regular matching? You can write a regular to match the picture you want.

Preg_match is it possible to use regular matching? You can write a regular to match the picture you want.



Yes, I matched to the first picture, but this picture does not meet my requirements! I want to match the 2nd one.

Sounds like it. Extract article thumbnails, filter small icons
The Preg_match_all function appears to return all matching results directly, if the article is too long or the picture does affect performance
Cycle Preg_match, each time you cut off the previous part of the matching article? How do I quickly get the location of a breakpoint?
Can you do it with Preg_replace_callback? Does the callback function have a way to end the keynote function?
In another way, is your text collected or published by users? The latter can be stored in the form of attachments to the storage of convenient management, using the Ueditor this type can be modified source code implementation

Preg_match_all Disposable Removal
Loop results, jump out if necessary (interrupt check)

Preg_match or strstr successive checks in the loop until the condition is met

The efficiency of the two is the same, and the problem of residual string judgment exists in Preg_match

For PHP 5.2, pure String functions can be used, character-by-word recognition. Efficiency is significantly higher than the use of regular
For PHP 5.3 and above, the two are quite efficient. Don't physician

It is recommended that the original string do strip_tags only keep the IMG tag, processing it up to several times faster

In addition, if the program does not follow the action (that is, allow die when the conditions are met)
Then Preg_replace_callback best suit your needs.

In addition, if the program does not follow the action (that is, allow die when the conditions are met)
Then Preg_replace_callback best suit your needs.



Thanks a lot!

Sounds like it. Extract article thumbnails, filter small icons
The Preg_match_all function appears to return all matching results directly, if the article is too long or the picture does affect performance
Cycle Preg_match, each time you cut off the previous part of the matching article? How do I quickly get the location of a breakpoint?
Can you do it with Preg_replace_callback? Does the callback function have a way to end the keynote function?
In another way, is your text collected or published by users? The latter can be stored in the form of attachments to the storage of convenient management, using the Ueditor this type can be modified source code implementation



Thank you, and you mentioned that storing the image as an attachment is all the pictures in the article stored in a separate table?

I am like this, in the article table to build another field, the article all the picture links in the comma-separated stored in this field! Use this field to manipulate the pictures stored on the disk, do not know how this?

Moderator proposed Strip_tags extract img tag sharply ah
Landlord said the single field management of multiple data separated by commas, only for the very individual case: no search, no sorting, a small number and so on, you can learn the database paradigm this east, White is the multi-data must be a separate table for easy management
The former son of a rookie CMS, the image of a separate table, upload to Ajax, return ID and SRC. After submitting some article fields and these several image IDs, modify the other fields of these pictures in the picture table to bind with the current article. Very convenient to manage.

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