Waarom werkt str_replace niet?
// Ik heb de laatste tijd visual basic the programeren
// String replace in VB heeft geet Set Variable nodig.
// Hier was de fout dat ik er geen set bij had.
Hey allemaal,
Ik ben een syntax hightlighter aan het maken.
Maar om een of andere reden werkt str_replace niet.
Ik ga ervan uit dat het aan mij ligt, dus kan iemand even hier naar kijken?
Het scriptje thuis draait met css stylesheet:
Preview hoe het eruit ziet + debug:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
function JassToSyntax( $Input ) {
global $LoopCount;
$Input = stripslashes( $Input );
echo $Input . "<br><br>";
function JassToSyntaxEnum( $Keyword, $Class, $Word ) {
global $LoopCount;
$KeywordArray = explode( ",", $Keyword );
$LoopCount = $LoopCount + 1;
for ( $i = 0; $i < count( $KeywordArray ); $i++ ) {
/*
If the word is the same as the parsed keyword array, continue with the script.
*/
if ( $KeywordArray[ $i ] == $Word ) {
/*
If the word was already found, it shouldn't beable to get past this.
*/
if ( $LoopCount != -100 ) {
/*
If its a string then do nothing. We don't want this to be looped 500 times.
*/
if ( substr( $Word, 0, 1 ) != '"' ) {
$Output = $Output . "<font class=".$Class.">".$Word."</font> ";
$LoopCount = -100;
}
}
}
}
/*
If Loopcount is the same as the parsed keyword amount and there is no word found ( -100 ) then its not a keyword.
*/
if ( $LoopCount == 3 and $IsString == false ) { $Output = $Output . $Word . " "; }
return stripslashes( $Output ); }
/*
These are all the keywords. Strings and integers are handled differntly.
*/
$KeywordsA = "endglobals,globals,endfunction,function,if,then,endif,loop,endloop";
$KeywordsB = "takes,returns,return,local,constant,set,exitwhen";
$KeywordsC = "boolean,integer,real,string,event,player,widget,unit,destructable,item,ability,buff,force,group,trigger,triggercondition,triggeraction,timer,location,region,rect,boolexpr,sound,conditionfunc,filterfunc,unitpool,itempool,race,alliancetype,racepreference,gamestate,igamestate,fgamestate,playerstate,playerscore,playergameresult,unitstate,aidifficulty,eventid,gameevent,playerevent,playerunitevent,unitevent,limitop,widgetevent,dialogevent,unittype,gamespeed,gamedifficulty,gametype,mapflag,mapvisibility,mapsettings,mapdensity,mapcontrol,playerslotstate,volumegroup,camerafield,camerasetup,playercolor,placement,startlocprio,raritycontrol,blendmode,texmapflags,effect,effectype,wearhereffect,terraindeformation,fogstate,fogmodifier,dialog,button,quest,questitem,defeatcondition,timerdialog,leaderboard,multiboard,multiboarditem,trackable,gamecache,version,itemtype,texttag,attacktype,damagetype,weapontype,soundtype,lightning,pathingtype,image,ubersplat";
/*
We are going to split the strings and replace new lines with HTML breaks.
After that, well explode the string to parse it trough everything.
*/
$Input = str_replace( "\r\n", " <br /> ", $Input );
$Input = str_replace( "\t", " ", $Input );
$InputArray = explode( " ", $Input );
for ( $i = 0; $i < count($InputArray); $i++ ) {
/*
Lets look for default keywords.
*/
$Output = $Output . JassToSyntaxEnum( $KeywordsA, "BlocksMain", $InputArray[ $i ] );
$Output = $Output . JassToSyntaxEnum( $KeywordsB, "keywordB", $InputArray[ $i ] );
$Output = $Output . JassToSyntaxEnum( $KeywordsC, "keywordC", $InputArray[ $i ] );
/*
Lets look for strings.
*/
if ( substr( $InputArray[ $i ], 0, 1 ) == '"' ) {
echo "Replacing: " . $InputArray[ $i ] . '<br/> ';
echo "With: " . '<font class="String">'.$InputArray[ $i ]."</font><br/>";
echo "In String: " . str_replace( "<br />", " ", $Output ) . '<br/><br/><br/> ';
// Hier zit het probleem.
// Probleem verholpen door: $Output = str_replace( $InputArray[$i], '<fon....
str_replace( $InputArray[$i], '<font class="String">'.$InputArray[ $i ].'</font> ', $Output );
}
$LoopCount = 0;
}
return $Output; }
?>
function JassToSyntax( $Input ) {
global $LoopCount;
$Input = stripslashes( $Input );
echo $Input . "<br><br>";
function JassToSyntaxEnum( $Keyword, $Class, $Word ) {
global $LoopCount;
$KeywordArray = explode( ",", $Keyword );
$LoopCount = $LoopCount + 1;
for ( $i = 0; $i < count( $KeywordArray ); $i++ ) {
/*
If the word is the same as the parsed keyword array, continue with the script.
*/
if ( $KeywordArray[ $i ] == $Word ) {
/*
If the word was already found, it shouldn't beable to get past this.
*/
if ( $LoopCount != -100 ) {
/*
If its a string then do nothing. We don't want this to be looped 500 times.
*/
if ( substr( $Word, 0, 1 ) != '"' ) {
$Output = $Output . "<font class=".$Class.">".$Word."</font> ";
$LoopCount = -100;
}
}
}
}
/*
If Loopcount is the same as the parsed keyword amount and there is no word found ( -100 ) then its not a keyword.
*/
if ( $LoopCount == 3 and $IsString == false ) { $Output = $Output . $Word . " "; }
return stripslashes( $Output ); }
/*
These are all the keywords. Strings and integers are handled differntly.
*/
$KeywordsA = "endglobals,globals,endfunction,function,if,then,endif,loop,endloop";
$KeywordsB = "takes,returns,return,local,constant,set,exitwhen";
$KeywordsC = "boolean,integer,real,string,event,player,widget,unit,destructable,item,ability,buff,force,group,trigger,triggercondition,triggeraction,timer,location,region,rect,boolexpr,sound,conditionfunc,filterfunc,unitpool,itempool,race,alliancetype,racepreference,gamestate,igamestate,fgamestate,playerstate,playerscore,playergameresult,unitstate,aidifficulty,eventid,gameevent,playerevent,playerunitevent,unitevent,limitop,widgetevent,dialogevent,unittype,gamespeed,gamedifficulty,gametype,mapflag,mapvisibility,mapsettings,mapdensity,mapcontrol,playerslotstate,volumegroup,camerafield,camerasetup,playercolor,placement,startlocprio,raritycontrol,blendmode,texmapflags,effect,effectype,wearhereffect,terraindeformation,fogstate,fogmodifier,dialog,button,quest,questitem,defeatcondition,timerdialog,leaderboard,multiboard,multiboarditem,trackable,gamecache,version,itemtype,texttag,attacktype,damagetype,weapontype,soundtype,lightning,pathingtype,image,ubersplat";
/*
We are going to split the strings and replace new lines with HTML breaks.
After that, well explode the string to parse it trough everything.
*/
$Input = str_replace( "\r\n", " <br /> ", $Input );
$Input = str_replace( "\t", " ", $Input );
$InputArray = explode( " ", $Input );
for ( $i = 0; $i < count($InputArray); $i++ ) {
/*
Lets look for default keywords.
*/
$Output = $Output . JassToSyntaxEnum( $KeywordsA, "BlocksMain", $InputArray[ $i ] );
$Output = $Output . JassToSyntaxEnum( $KeywordsB, "keywordB", $InputArray[ $i ] );
$Output = $Output . JassToSyntaxEnum( $KeywordsC, "keywordC", $InputArray[ $i ] );
/*
Lets look for strings.
*/
if ( substr( $InputArray[ $i ], 0, 1 ) == '"' ) {
echo "Replacing: " . $InputArray[ $i ] . '<br/> ';
echo "With: " . '<font class="String">'.$InputArray[ $i ]."</font><br/>";
echo "In String: " . str_replace( "<br />", " ", $Output ) . '<br/><br/><br/> ';
// Hier zit het probleem.
// Probleem verholpen door: $Output = str_replace( $InputArray[$i], '<fon....
str_replace( $InputArray[$i], '<font class="String">'.$InputArray[ $i ].'</font> ', $Output );
}
$LoopCount = 0;
}
return $Output; }
?>
Ik heb comments, dus je zou omgeveer moeten weten wat wat doet.
Gewijzigd op 01/01/1970 01:00:00 door Johan K
Er zijn nog geen reacties op dit bericht.