|
-
Aug 21st, 2002, 07:43 AM
#1
Thread Starter
Hyperactive Member
find characters that between
How can solve this problem.
________________________
I want code to test if there are any of this characters "+" or ":" or "(" or ")" or "&" between [wor] and [/wor] and give me true else false.
for example(s):
$text="hi [wor] : [/wor] bye"; // output >> true
$text="hi [wor] & how + [/wor] bye"; // output >> true
$text="hi [wor] can ( [/wor] bye"; // output >> true
$text="hi [wor] ) [/wor] bye"; // output >> true
$text="hi ) [wor] you [/wor] bye + & "; // output >> false
-
Aug 21st, 2002, 08:28 AM
#2
Conquistador
perhaps something like:
PHP Code:
function test($teststr){
$nStr = explode("[wor]", $teststr);
$pStr = explode("[/wor]", $nStr[1]);
echo $pStr[0];
if (ereg("+", $pStr[0]) || ereg(":", $pStr[0]) || ereg("(", $pStr[0]) || ereg(")", $pStr[0]) || ereg("&", $pStr[0])){
return 1;
} else {
return 0;
}
}
-
Aug 21st, 2002, 08:54 AM
#3
Thread Starter
Hyperactive Member
-
Aug 21st, 2002, 09:33 AM
#4
Conquistador
no worries
-
Aug 21st, 2002, 09:33 AM
#5
Lively Member
Prok, do you not understand any of the code we have given you in the past. what you want to do is with regular expressions and it is much faster.
if (preg_match('/[\+\(\)\&:]/',$string, $match)){
return 1;
} else {
return 0;
}
something to that effect.
Just Imagine what you can do with the power of php.
257 Tutorials and counting.
529 Snippets and growing.
Add yours today @
SnippetLibrary.com
-
Aug 21st, 2002, 10:49 AM
#6
Thread Starter
Hyperactive Member
[wor] and [/wor]
I said provide that text between [wor] and [/wor]
so use this code:
<?
$text="hi [wor] http:// [/wor] ( ";
$X=preg_match('#\[wor\]((?!\[/wor\]).)*[+ )&]((?!\[/wor\]).)*\[/wor\]#i', $text);
Echo $X;
?>
what is this ? ... that is not the code that I write it it's auto changed ..
so
it's here:
http://www.vbzoom.com/bank/show.php?...leName=PHPBank
Last edited by prokhaled; Aug 21st, 2002 at 10:57 AM.
-
Aug 21st, 2002, 01:59 PM
#7
Lively Member
well I am impressed. almost got it but not quite.
Code:
$text="hi ([wor] http:// [/wor]& bye; ( ";
if(preg_match('/\[(wor)\].*([:&()+]).*\[/U', $text, $match)){
echo "found something = ". $match[2];
}else{
echo "didn't find anything";
}
this will work adn tell you it found something (return true) on the first thing it finds.
Just Imagine what you can do with the power of php.
257 Tutorials and counting.
529 Snippets and growing.
Add yours today @
SnippetLibrary.com
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|