Php regular expression to extract the src address and any attributes of html images (img,
Simple version:
<? Phpheader ("Content-Type: text/html; charset = UTF-8 "); $ str = '<div class = "ui-block-a" align = "center"> <a href = "online-39.html" rel = "external nofollow">
Detailed version:
<? Php/* PHP Regular Expression extraction arbitrary attribute in image img mark */$ str = '<center> <br/> PHP Regular Expression extraction or modifying any attribute in the img mark of the image </center> '; // 1. Obtain the entire image code preg_match ('/<\ s * img \ s + [^>] *? Src \ s * = \ s * (\ '| \")(.*?) \ 1 [^>] *? \/? \ S *>/I ', $ str, $ match); echo $ match [0]; // 2. Retrieve widthpreg_match ('//I ', $ str, $ match); echo $ match [1]; // 3. Obtain heightpreg_match ('//I ', $ str, $ match); echo $ match [1]; // 4. Obtain srcpreg_match ('//I ', $ str, $ match); echo $ match [1]; /* PHP regular expression to replace any attribute in the img mark of the image * // 1. Replace src = "/uploads/images/20100516000.jpg" with src ="/uploads/uc/images/2017020716154162.jpg") print preg_replace ('/()/I ', "\$ {1} uc/images/\$ {3}", $ str); echo "
The above php Regular Expression extraction html image (img) src address and any attributes of the method is small make up to share with you all the content, hope to give you a reference, we also hope that you can support the customer's home.