[PHP] Wrong parameter count for str_replace()

Gestart doorJoeey12 reacties42 weergaven

13 berichten · pagina 1 van 1

Joeey

Lid · Topicstarter

Berichten
3.074
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hi,

Ik was bezig met een PHP highlighting functie, maar opeens kreeg ik een error. yummieNamelijk een warning met str_replace()

Warning: Wrong parameter count for str_replace() in /home/*****/domains/*****/public_html/PHPHighlighting.php on line 12

Hoe kan je deze error oplossen? Dit is mijn code:

[COLOR= #0000BB]<?php[/COLOR]    
[COLOR= #FF8000]/**
 * $errors[1] = Empty error
 * $errors[2] = String length error
 */[/COLOR]

[COLOR= #007700]function[/COLOR] PHPHighlighting[COLOR= #007700]()
{[/COLOR]
    [COLOR= #FF8000]/**
     * The highlighting function
     */[/COLOR]
    [COLOR= #0000BB]$strOutput[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]<?php[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]<font color="#FF0000"><?php</font>[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$php[/COLOR][COLOR= #007700]);[/COLOR]
    [COLOR= #0000BB]$strOutput[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]?>[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]<font color="#FF0000">?></font>[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$php[/COLOR][COLOR= #007700]);[/COLOR]
    [COLOR= #0000BB]$strOutput[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]echo[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]<font color="#0000FF">echo</font>[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$php[/COLOR][COLOR= #007700]);[/COLOR]
    [COLOR= #0000BB]$strOutput[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]print[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]<font color="#0000FF">print</font>[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$php[/COLOR][COLOR= #007700]);[/COLOR]
    [COLOR= #0000BB]$strOutput[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]return[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]<font color="#0000FF">return</font>[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$php[/COLOR][COLOR= #007700]);[/COLOR]
    [COLOR= #0000BB]$strOutput[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]array[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]<font color="#0000FF">array</font>[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$php[/COLOR][COLOR= #007700]);[/COLOR]
    [COLOR= #0000BB]$strOutput[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]function[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]<font color="#0000FF">function</font>[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$php[/COLOR][COLOR= #007700]);[/COLOR]
    [COLOR= #0000BB]$strOutput[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]class[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]<font color="#0000FF">class</font>[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$php[/COLOR][COLOR= #007700]);[/COLOR]
    [COLOR= #0000BB]$strOutput[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]die[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]<font color="#0000FF">die</font>[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$php[/COLOR][COLOR= #007700]);[/COLOR]
    
    [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$strOutput[/COLOR][COLOR= #007700];
}[/COLOR]

[COLOR= #FF8000]/**
 * Checks if POST is used
 */[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REQUEST_METHOD[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]"POST"[/COLOR][COLOR= #007700])
{[/COLOR]
    [COLOR= #FF8000]/**
     * Makes an array for errors 
     */[/COLOR]
    [COLOR= #0000BB]$errors[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/Array"]Array[/URL][COLOR= #007700]();[/COLOR]    
    [COLOR= #FF8000]/**
     * Rewrites and secures $_POST[PHP]
     */[/COLOR]
    [COLOR= #0000BB]$php[/COLOR] [COLOR= #007700]=[/COLOR] htmlentities[COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]PHP[/COLOR][COLOR= #007700]]);[/COLOR]
    
    [COLOR= #FF8000]/**
     * Checks if field is empty
     */[/COLOR]
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/empty"]empty[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$php[/COLOR][COLOR= #007700]))
    {[/COLOR]
        [COLOR= #0000BB]$errors[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]] =[/COLOR] [COLOR= #DD0000]Je moet wel een veld invullen![/COLOR][COLOR= #007700];
    }[/COLOR]
    [COLOR= #FF8000]/**
     * Checks if string length is smaller then 5 characters
     */[/COLOR]
    [URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/strlen"]strlen[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$php[/COLOR][COLOR= #007700]) <[/COLOR] [COLOR= #0000BB]5[/COLOR][COLOR= #007700])
    {[/COLOR]
        [COLOR= #0000BB]$errors[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]2[/COLOR][COLOR= #007700]] =[/COLOR] [COLOR= #DD0000]Je code moet langer zijn dan 5 tekens![/COLOR][COLOR= #007700];
    }[/COLOR]
    [URL="http://www.php.net/else"]else[/URL]
    [COLOR= #007700]{[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] PHPHighlighting[COLOR= #007700]([/COLOR][URL="http://www.php.net/nl2br"]nl2br[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$php[/COLOR][COLOR= #007700]));
    }
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL]
[COLOR= #007700]{[/COLOR]
?>
<form method="POST" action="">
    <label for="PHP">PHP:</label><br />
    <input type="text" name="PHP" /><br /><br />
    
    <input type="submit" name="submit" value="Submit" />
</form>
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]}[/COLOR]
?>


Alvast bedankt! hypocrite
- Joey
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Er mist nog een derde parameter, de input parameter.

toevoeging op 27 mei 2012, 181536:
    $strOutput = str_replace(, $input);
0
Joeey

Lid · Topicstarter

Berichten
3.074
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Sevvlor schreef:
Er mist nog een derde parameter, de input parameter.
toevoeging op 27 mei 2012, 181536:
    $strOutput = str_replace(, $input);

Waar komt die $input dan vandaan? Ik bedoel, het moet toch een waarde hebben? bloos
// Laat maar, het werkt. smile
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Joeyl schreef:
Eerdere citaten tonen
Sevvlor schreef:
Er mist nog een derde parameter, de input parameter.
toevoeging op 27 mei 2012, 181536:
    $strOutput = str_replace(, $input);

Waar komt die $input dan vandaan? Ik bedoel, het moet toch een waarde hebben? bloos
Ja, de input is de text waar de str_replace op wil toepassen.
0
Joeey

Lid · Topicstarter

Berichten
3.074
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Nog een probleem, hij wilt niets weergeven als ik iets invoer, ook geen errors.
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
function PHPHighlighting($php){
    /**
     * The highlighting function
     */
    $strOutput = str_replace(<?php, <font color="#FF0000"><?php</font>, $php);
    $strOutput = str_replace(?>, <font color="#FF0000">?></font>, $php);
    $strOutput = str_replace(echo, <font color="#0000FF">echo</font>, $php);
    $strOutput = str_replace(print, <font color="#0000FF">print</font>, $php);
    $strOutput = str_replace(return, <font color="#0000FF">return</font>, $php);
    $strOutput = str_replace(array, <font color="#0000FF">array</font>, $php);
    $strOutput = str_replace(function, <font color="#0000FF">function</font>, $php);
    $strOutput = str_replace(class, <font color="#0000FF">class</font>, $php);
    $strOutput = str_replace(die, <font color="#0000FF">die</font>, $php);
    
    return $strOutput;
}


toevoeging op 27 mei 2012, 18:24:10:
je vergat de input in de functie zelf te zetten
0
Joeey

Lid · Topicstarter

Berichten
3.074
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Sevvlor schreef:
function PHPHighlighting($php){
    /**
     * The highlighting function
     */
    $strOutput = str_replace(<?php, <font color="#FF0000"><?php</font>, $php);
    $strOutput = str_replace(?>, <font color="#FF0000">?></font>, $php);
    $strOutput = str_replace(echo, <font color="#0000FF">echo</font>, $php);
    $strOutput = str_replace(print, <font color="#0000FF">print</font>, $php);
    $strOutput = str_replace(return, <font color="#0000FF">return</font>, $php);
    $strOutput = str_replace(array, <font color="#0000FF">array</font>, $php);
    $strOutput = str_replace(function, <font color="#0000FF">function</font>, $php);
    $strOutput = str_replace(class, <font color="#0000FF">class</font>, $php);
    $strOutput = str_replace(die, <font color="#0000FF">die</font>, $php);
    
    return $strOutput;
}
toevoeging op 27 mei 2012, 18:24:10:
je vergat de input in de functie zelf te zetten

Ah, dat was een stomme denkfout.
Maar hij doet het nog niet, ligt denk ik aan de $_POST...
Zal er even naar kijken.
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Andere vraag:
Waarom gebruik je een oeroude ?
0
Joeey

Lid · Topicstarter

Berichten
3.074
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Aarclay schreef:
Andere vraag:
Waarom gebruik je een oeroude ?
Omdat je dat kan gebruiken...
Sebastiaanh schreef:
Waarom moeilijk doen als t ook makkelijk kan?
http://php.net/manual/en/function.highlight-string.php
Oh, ik wist niet dat dat bestond. yummie
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Joeyl schreef:
Eerdere citaten tonen
Aarclay schreef:
Andere vraag:
Waarom gebruik je een oeroude ?

Omdat je dat kan gebruiken...
Dat je het kan gebruiken, wil niet zeggen dat het nog correct is, tenzij je een oeroude doctype gebruikt, en daarmee je site niet goed compatible kan krijgen in diverse browsers.

Dus gebruik gewoon het style-attribuut... En verdiep je in CSS.
0
Joeey

Lid · Topicstarter

Berichten
3.074
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Aarclay schreef:
Eerdere citaten tonen
Joeyl schreef:
Eerdere citaten tonen
Aarclay schreef:
Andere vraag:
Waarom gebruik je een oeroude ?

Omdat je dat kan gebruiken...
Dat je het kan gebruiken, wil niet zeggen dat het nog correct is, tenzij je een oeroude doctype gebruikt, en daarmee je site niet goed compatible kan krijgen in diverse browsers.

Dus gebruik gewoon het style-attribuut... En verdiep je in CSS.
Oh, ik dacht dat het niet veel verschil maakte... Zal voortaan wel een class maken in mijn stylesheet.
0
Berichten
18.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Waarom een aparte functie hiervoor maken als je ook highlight_string() kunt gebruiken?
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren