2017-12-19 4 views
2

피드에서 데이터를 가져올 때 som 문자를 바꿔야합니다. 어떻게 올바른 URL을 만들기 위해 하나의 두 기능을 병합 할 수 있는지 잘 모르겠습니다.두 함수 str_replace를 병합 하시겠습니까?

하나의 기능을 다른 기능에 넣으려고했으나 작동하지 않았습니다.

https://www.xxxxxx.se/brand/[my_custom_function2([my_custom_function3 ({브랜드 [1]})])]/

은 어떻게 하나에 다음과 같은 두 가지 결합 할 수 있습니다?

<?php 
function my_custom_function2($string) { 
    $string = str_replace (" ", "-", $string); 
    return $string; 
} 
function my_custom_function3($string) { 
    $string = str_replace ("Aéryne", "Aeryn", $string); 
    return $string; 
} 
?> 

고마워요!

추신. 나는 수백 개의 브랜드를 가지고 있으며, 일부는 두 단어입니다. 예 : "Billi Bi". 그것이 첫 번째 기능이 필요한 이유입니다.

+0

함수에 함수를 두는 것이 효과적입니다. 그렇지 않으면 반환 선 앞에 func3에서 func2로 str_replace를 복사합니다. – Martijn

+0

매개 변수가'mixed'이며,'str_replace (array ("", "A ryne"), array ("-", Aeryn "), $ string); ' –

답변

1

당신은 n 개의 않는 str_replace를 필요로하지 않는 하나의 기능에 이상 str_replace

str_replace (array("Aéryne"," "), array("Aeryn","-"), $string); 

랩에 배열을 전달하여 단일 호출을 사용하여 여러 문자를 대체 할 수있는 전화를해야 n 문자를 대체하려면

0
<?php 
function combine_functions($string){ 
    $string = my_custom_function2($string); 
    $string = my_custom_function3($string); 
    return $string; 
} 
function my_custom_function2($string) { 
    $string = str_replace (" ", "-", $string); 
    return $string; 
} 
function my_custom_function3($string) { 
    $string = str_replace ("Aéryne", "Aeryn", $string); 
    return $string; 
} 
?> 

이) (이

+0

정말 고마워요. ! –

0

이렇게 함수를 호출하지 않는 이유는 무엇입니까? $ result = my_custom_function2 (my_custom_function3 (brand [1])));

$ url = "https://www.xxxxxx.se/brand/ {$ result} /";

관련 문제