-
Q:
[php] Karakters uit variabele verwijderen
Ik heb een form en als IE-gebruikers die invullen worden er op een of andere manier paragrafen van gemaakt. Safari heeft hier geen last van.
Als ik de inhoud van dat form weergeef d.m.v. de variabele te echoën, dan zijn er i.p.v. enters witregels. Hoe haal ik de de waarde ‘<p>’ en ‘</p>’ uit de variabele van het form?*edit*
HTML uitgeschakeld.”TheVan de handleiding van php.net word ik nooit wijzer. Ik heb nu dit:
[code:1:4c02ffa4a1]$content = str_ireplace('<p>’, ”, ‘$content’);[/code:1:4c02ffa4a1]
Maar dan krijg ik i.p.v. het bericht letterlijk “$content” te zien.
waarom zet je dan een variabelen ook tussen quotes ? is nooit nodig namelijk he … Haal dat er dus eens uit ?
Ja daar kwam ik net ook achter, en dan werkt het
Ik controleer nu op ‘<p>’ en ‘</p>’ (hoofdletterongevoelig) d.m.v.:
[code:1:2d058c0c10]$content = str_ireplace('<p>’, ”, $content);
$content = str_ireplace('</p>’, ”, $content);[/code:1:2d058c0c10]Kan dit nog efficiënter?
[code:1:f10673400c]$comment = str_replace(’:)’, ‘<img src="emoticons/smile.png">’, $comment);
$comment = str_replace(’:-)’, ‘<img src="emoticons/smile.png">’, $comment);$comment = str_replace(’;)’, ‘<img src="emoticons/wink.png">’, $comment);
$comment = str_replace(’;-)’, ‘<img src="emoticons/wink.png">’, $comment);$comment = str_replace(’:D’, ‘<img src="emoticons/grin.png">’, $comment);
$comment = str_replace(’:-D’, ‘<img src="emoticons/grin.png">’, $comment);$comment = str_ireplace(’:p’, ‘<img src="emoticons/yuck.png">’, $comment);
$comment = str_ireplace(’:-p’, ‘<img src="emoticons/yuck.png">’, $comment);$comment = str_ireplace(’(H)’, ‘<img src="emoticons/cool.png">’, $comment);
$comment = str_replace(’8)’, ‘<img src="emoticons/cool.png">’, $comment);
$comment = str_replace(’8-)’, ‘<img src="emoticons/cool.png">’, $comment);$comment = str_ireplace(’(a)’, ‘<img src="emoticons/innocent.png">’, $comment);
$comment = str_replace(’:$’, ‘<img src="emoticons/embarrassed.png">’, $comment);
$comment = str_replace(’:-$’, ‘<img src="emoticons/embarrassed.png">’, $comment);$comment = str_replace(’:(’, ‘<img src="emoticons/frown.png">’, $comment);
$comment = str_replace(’:-(’, ‘<img src="emoticons/frown.png">’, $comment);$comment = str_replace(’:/’, ‘<img src="emoticons/slant.png">’, $comment);
$comment = str_replace(’:-/’, ‘<img src="emoticons/slant.png">’, $comment);$comment = str_replace(’:#’, ‘<img src="emoticons/sealed.png">’, $comment);
$comment = str_replace(’:-#’, ‘<img src="emoticons/sealed.png">’, $comment);$comment = str_replace(’(6)’, ‘<img src="emoticons/naughty.png">’, $comment);[/code:1:f10673400c]
Dat gaat allemaal goed, maar deze gaat mis:
[code:1:f10673400c]$comment = str_replace(":’(", "<img src=’emoticons/cry.png’>", $comment);[/code:1:f10673400c]
Nee, het weergeven. Hier de complete code, dit is de hele functie om de reacties te laten zien:
[code:1:f3851ec027]//
// Reacties laten zien
//function DisplayComments(){
// Instellingen
include("settings.php");// Verbinding maken
Connect();if (isset($_GET[’show’]))
{
$all = $_GET[’show’];
}$count = 0;
$all = "10";
$page = (isset($_GET[’page’]) && is_numeric($_GET[’page’])) ? $_GET[’page’] : 1;
if ($page<1) {
$page = 1;
}$from = $page * $all – $all;
$count = 0;
$result = mysql_query("SELECT COUNT(*) as count FROM comments")
or die("Error fetching number in DB<br>".mysql_error());
$row = mysql_fetch_array($result);
$numofrows = $row[’count’];
$pages = ceil($numofrows / $all);$query = "SELECT * FROM comments ORDER BY id DESC LIMIT ".$from.", ".$all."";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);// Welke pagina?
if ($page > $numofrows){
echo "";
}
else{
echo "<p>Dit is pagina $page van $pages</p>";
}if (!$numrows == ""){
while($row = mysql_fetch_array($result)){$name = Secure($row[’name’]);
$website = Secure($row[’website’]);
$email = Secure($row[’email’]);
$comment = htmlentities($row[’comment’]);
$date = $row[’date’];
$on = date(’l j M Y’, strtotime($row[’date’]));$maand[’Jan’]="januari";
$maand[’Feb’]="februari";
$maand[’Mar’]="maart";
$maand[’Apr’]="april";
$maand[’May’]="mei";
$maand[’Jun’]="juni";
$maand[’Jul’]="juli";
$maand[’Aug’]="augustus";
$maand[’Sep’]="september";
$maand[’Oct’]="oktober";
$maand[’Nov’]="november";
$maand[’Dec’]="december";foreach($maand as $k=>$v){
$on=str_replace($k, $v, $on);
}$dag[’Monday’]="maandag";
$dag[’Tuesday’]="dinsdag";
$dag[’Wednesday’]="woensdag";
$dag[’Thursday’]="donderdag";
$dag[’Friday’]="vrijdag";
$dag[’Saturday’]="zaterdag";
$dag[’Sunday’]="zondag";foreach($dag as $k=>$v){
$on=str_replace($k, $v, $on);
}$at = date(’H:i’, strtotime($row[’date’]));
$comment = str_replace(’:)’, ‘<img src="emoticons/smile.png">’, $comment);
$comment = str_replace(’:-)’, ‘<img src="emoticons/smile.png">’, $comment);$comment = str_replace(’;)’, ‘<img src="emoticons/wink.png">’, $comment);
$comment = str_replace(’;-)’, ‘<img src="emoticons/wink.png">’, $comment);$comment = str_replace(’:D’, ‘<img src="emoticons/grin.png">’, $comment);
$comment = str_replace(’:-D’, ‘<img src="emoticons/grin.png">’, $comment);$comment = str_ireplace(’:p’, ‘<img src="emoticons/yuck.png">’, $comment);
$comment = str_ireplace(’:-p’, ‘<img src="emoticons/yuck.png">’, $comment);$comment = str_ireplace(’(H)’, ‘<img src="emoticons/cool.png">’, $comment);
$comment = str_replace(’8)’, ‘<img src="emoticons/cool.png">’, $comment);
$comment = str_replace(’8-)’, ‘<img src="emoticons/cool.png">’, $comment);$comment = str_ireplace(’(a)’, ‘<img src="emoticons/innocent.png">’, $comment);
$comment = str_replace(":’(", "<img src=’emoticons/cry.png’>", $comment);
$comment = str_replace(’:$’, ‘<img src="emoticons/embarrassed.png">’, $comment);
$comment = str_replace(’:-$’, ‘<img src="emoticons/embarrassed.png">’, $comment);$comment = str_replace(’:(’, ‘<img src="emoticons/frown.png">’, $comment);
$comment = str_replace(’:-(’, ‘<img src="emoticons/frown.png">’, $comment);$comment = str_replace(’:/’, ‘<img src="emoticons/slant.png">’, $comment);
$comment = str_replace(’:-/’, ‘<img src="emoticons/slant.png">’, $comment);$comment = str_replace(’:#’, ‘<img src="emoticons/sealed.png">’, $comment);
$comment = str_replace(’:-#’, ‘<img src="emoticons/sealed.png">’, $comment);$comment = str_replace(’(6)’, ‘<img src="emoticons/naughty.png">’, $comment);
$color = ($count % 2) ? $color1 : $color2;
$border = ($count % 2) ? $border1 : $border2;echo "<div class=’comm’ style=’background:$color;border-top:1px solid $border;border-bottom:1px solid $border;’>";
if ($website == "http://"){
echo "<span class=’by’>$name</span>";
}
else if ($website == "") {
echo"<br /><span class=’time’>$on @ $at</span><p>";
}
else{
echo "<span class=’by’><a target="_blank" href="$website">$name</a></span>";
}echo"<span class=’time’> op $on, $at</span><br><br><div class="comment">";
echo BBCode($comment);
echo "</div></div>";
$count++;}
echo "<div class=’nav’>";// Vorige
if ($page>1) {
$xpage = $page;
$xpage–;
echo "<div class=’left’><a title=’Vorige $all berichten’ class=’prev’ href=’index.php?show=$all&page=$xpage’>Vorige</a></div>";
}// Volgende
if ($page<$pages) {
$xpage = $page;
$xpage++;
echo "<div class=’right’><a title=’Volgende $all berichten’ class=’next’ href=’index.php?show=$all&page=$xpage’>Volgende</a></div>";
}echo "</div>";
}
// Als er geen reacties zijn
else{
echo "<div class=’comm’ style=’background:white;border-top:1px solid black;border-bottom:1px solid black;’>Er zijn nog geen berichten in het gastenboek.</div>";
}mysql_close();
}[/code:1:f3851ec027]
Je moet ingelogd zijn om een reactie op dit onderwerp te kunnen geven.