PHP Forum

PHP Forum (http://www.selfphp.de/forum/index.php)
-   PHP Grundlagen (http://www.selfphp.de/forum/forumdisplay.php?f=12)
-   -   Probleme mit Sonderzeichen ! (http://www.selfphp.de/forum/showthread.php?t=17216)

Php-NooB 11.07.2007 06:12:31

Probleme mit Sonderzeichen !
 
Hallo ihr da !

Ich habe mir für den Winamp ein Plugin besorgt, das einem die Möglichkeit gibt auf seiner HP anzeigen zu lassen, welches Lied gerade im Winamp läuft.
Es läd die Daten in bestimmten Intervallen auf den FTP server hoch und erstellt durch ein vorgegebenes Templete dann eine html bzw. php Seite.

Das originale Templete ist HTML Templete...

Dieses habe ich mir jetzt nach meinen optischen und technischen Bedürfnissen angepasst und mit meinen fast nicht vorhandenen PHP Kenntnissen und viel googlen so umgeschrieben das es läuft... (ist jetzt also auch keine HTML mehr sondern eine PHP Datei)

soweit so gut...

In dem originalen Template (HTML) werden wenn jetzt z.B. ein Interpret oder ein Titel Sonderzeichen wie ( / und ' und + und & usw.) enthält es ohne Probleme dargestellt.
In meinem umgeschrieben Templete (PHP) verursacht dieses natürlich einen Fehler.

Meine Frage ist, wie kann ich dieses jetzt umgehen ?

Ich habe schon öfters in Google gelesen, dass man mit
?> HTMLTEXT <?php
im PHP Script das PHP "abschalten" kann und dann HTML Code eingeben kann !
Hab ich auch gemacht, erziehlt aber nicht das gewünschte Ergebnis, bei Sonderzeichen bekomme ich weiterhin einen Scriptfehler.

Kann mir hier vielleicht Jemand weiterhelfen ?
Wäre super nett ! Danke...

Ich hänge mal mein Templete an, aber nicht wundern, wie gesagt, ich habe 0 Ahnung ;-)

Teilauszug: (weil Text zu lang ist... im anderen Teil kommt noch Artist und Title von 1-15 vor, aber fast gleicher Aufbau)

Code:

<?php

switch(@$_GET['action']) {
        case("now"):
{

?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="cache-control" content="must-revalidate">
<meta http-equiv="refresh" content="30; url=index.php?action=now">
<title>Winamp</title>
</head>

<style type="text/css">
<!--
a:link { text-decoration:none; }
a:visited { text-decoration:none; }
a:hover { text-decoration:none;}
a:active { text-decoration:none; }
-->
</style>

<body link="#F2C118" vlink="#F2C118" alink="#F2C118" style="background-color:transparent">

<?php

[np:IsPlaying]

if ('[np:Length1]' == "")
    {
    print('<b><font color="#C0C0C0" face="Verdana" size="2">Aktueller Titel im Winamp: </font></b><font color="#F2C118" face="Verdana" size="2"><a target="haupt" href="index.php?action=last">Es wird ein Internetstream abgespielt.</a></font>');
    }
  else
    {
if ('[np:Artist1]' == "")
    {
    ?><b><font color="#C0C0C0" face="Verdana" size="2">Aktueller Titel im Winamp: </font></b><font color="#F2C118" face="Verdana" size="2"><a target="haupt" href="index.php?action=last">[np:Title1] </font><font color="#C0C0C0" face="Verdana" size="2">[[np:Length1]]</a></font><?php
    }
  else
    {
    ?><b><font color="#C0C0C0" face="Verdana" size="2">Aktueller Titel im Winamp: </font></b><font color="#F2C118" face="Verdana" size="2"><a target="haupt" href="index.php?action=last">[np:Artist1] - [np:Title1] </font><font color="#C0C0C0" face="Verdana" size="2">[[np:Length1]]</a></font><?php
    }
    }

[/np:IsPlaying]
[np:NotPlaying]
print('<b><font color="#C0C0C0" face="Verdana" size="2">Aktueller Titel im Winamp: </font></b><font color="#F2C118" face="Verdana" size="2"><a target="haupt" href="index.php?action=last">Winamp ist aus oder hat keine Verbindung zum Internet.</a></font>');
[/np:NotPlaying]
}
}
?>
</body>
</html>

<?php
switch(@$_GET['action']) {
        case("last"):
{
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="cache-control" content="must-revalidate">
<meta http-equiv="refresh" content="60; url=index.php?action=last">
<title>Winamp</title>
</head>
<body link="#C0C0C0" vlink="#C0C0C0" alink="#C0C0C0" topmargin="10" marginheight="10"  leftmargin="10" marginwidth="10" scroll="auto" background="bg.jpg" style="background-attachment: fixed">

[np:IsPlaying]

<p class="MsoNormal"><font size="2" color="#F2C118">
<span style="font-family: Verdana; font-weight: 700">Winamp</span></p>
<b>
<p class="MsoNormal"><font face="Verdana" size="2" color="#C0C0C0">Zuletzt
gespielte Titel im Winamp:</font></p></b>

<?
if ('[np:Length1]' == "")
    {
    print('<font color="#C0C0C0" face="Verdana" size="2">01. </font><font color="#F2C118" face="Verdana" size="2">Es wird ein Internetstream abgespielt</font>');
    }
  else
    {
if ('[np:Artist1]' == "")
    {
    ?><font color="#C0C0C0" face="Verdana" size="2">01. </font><font color="#F2C118" face="Verdana" size="2">[np:Title1] </font><font color="#C0C0C0" face="Verdana" size="2">[[np:Length1]]</font><?
    }
  else
    {
    ?><font color="#C0C0C0" face="Verdana" size="2">01. </font><font color="#F2C118" face="Verdana" size="2">[np:Artist1] - [np:Title1] </font><font color="#C0C0C0" face="Verdana" size="2">[[np:Length1]]</font><?
    }
    }
?>
<br>
[/np:IsPlaying]
[np:NotPlaying]

<p class="MsoNormal"><font size="2" color="#F2C118">
<span style="font-family: Verdana; font-weight: 700">Winamp</span><span style="font-size: 10.0pt; font-family: Verdana; color: #F2C118"><b>
</b>
</span><b>
<font color="#C0C0C0">»</font> </b><span style="font-family: Verdana">ist aus oder hat keine Verbindung zum Internet</span></p>
<b>
<p class="MsoNormal"><font face="Verdana" size="2" color="#C0C0C0">Zuletzt
gespielte Titel im Winamp:</font></p></b>

<?
if ('[np:Length1]' == "")
    {
    print('<font color="#C0C0C0" face="Verdana" size="2">01. </font><font color="#F2C118" face="Verdana" size="2">Es wurde ein Internetstream abgespielt</font>');
    }
  else
    {
if ('[np:Artist1]' == "")
    {
    ?><font color="#C0C0C0" face="Verdana" size="2">01. </font><font color="#F2C118" face="Verdana" size="2">[np:Title1] </font><font color="#C0C0C0" face="Verdana" size="2">[[np:Length1]]</font><?
    }
  else
    {
    ?><font color="#C0C0C0" face="Verdana" size="2">01. </font><font color="#F2C118" face="Verdana" size="2">[np:Artist1] - [np:Title1] </font><font color="#C0C0C0" face="Verdana" size="2">[[np:Length1]]</font><?
    }
    }
?>
<br>
[/np:NotPlaying]

<?
if ('[np:Length2]' == "" && '[np:Artist2]' == "" && '[np:Title2]' == "")
    {
    print('');
    }
elseif ('[np:Length2]' == "")
    {
    print('<font color="#C0C0C0" face="Verdana" size="2">02. </font><font color="#F2C118" face="Verdana" size="2">Es wurde ein Internetstream abgespielt</font>');
    }
  else
    {
if ('[np:Artist2]' == "")
    {
    ?><font color="#C0C0C0" face="Verdana" size="2">02. </font><font color="#F2C118" face="Verdana" size="2">[np:Title2] </font><font color="#C0C0C0" face="Verdana" size="2">[[np:Length2]]</font><?
    }
  else
    {
    ?><font color="#C0C0C0" face="Verdana" size="2">02. </font><font color="#F2C118" face="Verdana" size="2">[np:Artist2] - [np:Title2] </font><font color="#C0C0C0" face="Verdana" size="2">[[np:Length2]]</font><?
    }
    }
?><br><?
.
.
.
Das ganze jetzt bis 15 !


Socrates 11.07.2007 11:48:45

AW: Probleme mit Sonderzeichen !
 
Morgen!
Wenn du Sonderzeichen mit PHP ausgeben willst, die in PHP als solche Sonderzeichen gelten, musst du vor diese ein \ schreiben. Dann funktioniert es. Du kannst die Ausgabe aber auch einfach auf Latin umwandeln. Dann hast du das ganze Problem nicht mehr. Die funktion dafür heißt htmlentities().
MfG, Andy

Php-NooB 12.07.2007 06:49:59

AW: Probleme mit Sonderzeichen !
 
danke erstmal für deine antwort...

aber ich glaube das war auch nicht so wirklich das problem, ich denke oder vermute bei genauerem betrachten mal eher das dieses das hauptproblem ist:

if ('[np:Artist1]' == "")
{

usw... und bei Title1 auch ... bzw. bei der ganzen reihe von 1 - 15 durch !

die variable [np:Artist1] kann ja auch schon so ein sonderzeichen beinhalten und dadurch kommt das zu einem fehler... wie kann ich das denn beheben oder umgehen ?


Alle Zeitangaben in WEZ +2. Es ist jetzt 13:18:35 Uhr.

Powered by vBulletin® Version 3.8.3 (Deutsch)
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.