2012-08-05 78 views
-2

有什么办法可以像做一个默认的代码,我不知道如何解释这个,但我会尽我所能。默认字数为Php

<?php 
if ($test == "CODE-*AnyWordHere*"){ 
    echo "Yes"; 
} 
?> 

又如:

<?php 
if ($url == "http://stackoverflow.com/secretplace/index.html/?*AnyWordHere*"){ 
    echo "Yes"; 
} 
?> 
+0

我不了解别人,但我不明白你想要什么...... – Oussama 2012-08-05 01:31:44

+1

真的吗?您选择并编码标记*每行*?您可以选择整个代码块并单击'{}'。 – 2012-08-05 01:31:57

+0

不明白这个问题。 – 2012-08-05 01:35:03

回答

0

如果我理解你的问题正确,你正在寻找strstr将匹配,看看是否一个字符串包含另一个字符串是这样的:

<?php 
    $email = 'http://stackoverflow.com/secretplace/index.html/?someTerm'; 
    $domain = strstr($email, 'someTerm'); 
    if ($domain) 
    { 
     // Your 'someTerm' was found in the string. 
    } 
?> 
+0

其不适合搜索 – 2012-08-05 01:36:24

+0

@MatthewJones对不起,我只是不明白你是什么问,然后:( – Fluffeh 2012-08-05 01:37:05

0

您可以尝试使用strpos()或:

function strending($string, $keyword){ 
    return substr($string, strlen($string)-strlen($keyword), strlen($string)) == $keyword; 
} 

strending("hello world", "world"); //true 
strending("hello world!", "world"); //false 

不知道这是不是你的意思。您也可以尝试使用regexp

1

我不确定你在找什么,但这里有一些猜测。

如果要检查if语句中的变量字符串,可以使用strstr或strpos来查看另一个字符串是否存在。要使用你提供的示例,请尝试以下操作:

<?php 
if (strstr($test, "CODE-")) { 
    echo "Yes"; 
} 
?> 

如果你想找回你正在检查的字符串变量的一部分,试试这个:

<?php 
$str_to_check = "CODE-*AnyWordHere*" 

if ($pos = strpos($test, $str_to_check) !== false)) { 
    $code = substr($str_to_check, $pos, len($str_to_check)); 
    echo $code; 
} 
?> 

如果你只是想使用控制语句中的可变字符串,请尝试以下操作:

<?php 
if ($test == "CODE-" . $any_word_here){ 
    echo "Yes"; 
} 
?> 

期间将两个字符串连接(连接)在一起。

如果这些都不够,那么我不确定你在问什么。