2012-07-16 5 views
-2

문자열은 다음과 같습니다. [slide image = "http://themes.devatic.com/konzept/wp-content/themes/konzept/includes/uploadify/uploads/bas_006.jpg"slide_desc = 그것에서 "= 이미지" 문자열에서 이미지 URL 가져 오기

방법 후 부품을 얻을 수? "한마디로

+2

는 어떤 언어 사용중인/당신은 무엇을 시도? – SLaks

+0

[슬라이드 이미지 = "및"slide_desc = "빈 문자"로 대체하십시오. " – GTSouza

답변

2

, 2 문자열 사이에 데이터를 가져 오기 위해 정규식을 사용합니다. 대부분의 경우, 서로 다른 언어와 같은 등록 표현식 그냥 작동한다 잘.

PHP에서

, 당신은 preg_match를 사용하려는 것입니다.

$string = "[slide image=\"http://themes.devatic.com/konzept/wp-content/themes/konzept/includes/uploadify/uploads/bas_006.jpg\" slide_desc=\"" 
preg_match("/image=\"(.*)\"/i", $string, $results) 
var_dump($results) 

업데이트 정규식 (좀 더 엄격한) : 사용되는 언어에 어떤 문맥에 의존하는 것 모두

/image\="([^"]*)"/i 

모든

. RegEx를 사용하면 훨씬 더 발전 할 수 있지만, 이것은 단지 &입니다.

enter image description here

전체 PHP 코드 예 :

<?php 
$string = '[slide image="http://themes.devatic.com/konzept/wp-content/themes/konzept/includes/uplo‌​adify/uploads/bas_006.jpg" slide_desc="<h4>Promotional Package</h4> Project description sentence" text_color="#464646" slide_horizontal="false"] [slide image="http://themes.devatic.com/konzept/wp-content/themes/konzept/includes/uplo‌​adify/uploads/bas_005.jpg" slide_desc="<h4></h4>" text_color="#464646" slide_horizontal="false"]'; 
preg_match_all('/image\="([^"]*)"/i', $string, $results); 
foreach ($results[1] as $res): 
    echo 'Image URL:'.$res."\n"; 
endforeach; 
?> 
+0

괜찮 았지만,이 코드 예를 들면 : '[slide image ="http://themes.devatic.com/ 프로모션 패키지 프로젝트 설명 문장 "text_color ="# 464646 "slide_horizontal ="false "] [슬라이드 이미지 ="kozept/wp-content/themes/konzept/포함/업로드/업로드/http://themes.devatic.com/konzept/wp-content/themes/konzept/includes/uploadify/uploads/bas_005.jpg "slide_desc ="

"text_color ="# 464646 "slide_horizontal ="false "] ' 그리고 모든 이미지 URL을 가져 오는 방법 –

+0

PHP 함수를 사용합니다 (http://php.net/manual/en/function.pre). g-match-all.php (PHP를 사용하는 경우) – CrazyVipa

+0

은 정규식 코드를 업데이트하고 스크린 샷을 추가했습니다. 정규식 코드를 테스트 할 수도 있습니다. 위의 사이트를 항상 사용합니다. www.rubular.com – CrazyVipa