Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP: Dringend Hilfe benötigt !

Empfohlene Antworten

Veröffentlicht

Hi zusammen!

Ich hab hier eine etwas komplizierte Aufgabenstellung und weiss nicht wie ich das lösen kann. Vielleicht ist hier ein Pro dabei und kann mir auf die Sprünge helfen ... (ich mach immer alles komplizierter als es ist).

Aufgabe: Funktion schreiben (replacevars)

$antwortneu = replacevars($anfrage,$antwort)

Beispiel:

-----------

antwort = ' entry.php3?id=Seite49 '&asid=<#id1>&bsid=<#id2>' [... usw.]

anfrage = ' /suchtprobleme/text.php3?id1=10&id2=20 ' [...usw.]

Die Funktion muss dann quasi die URL aufsplitten und die Werte (z.Bsp. id=10) rausziehen und den vorgegebenen Text (<#id1>) mit dem Wert ersetzen. Im Prinzip nicht schwierig, aber ich kapier's einfach net.

Das Ergebnis könnte dann wie folgt aussehen:

$antwortneu ='entry.php3?id=Seite49 '&asid=10&bsid=20'

Ich freue mich auf jede Antwort, jeden Tip, jede Lösung =)

Vielen lieben Dank im Vorraus !!!

bevor ich mir den kopf darüber zerbreche erstma ne frage:

warum so umständlich?

kannste mit nem template system nicht besser vorrankommen?

meinst du sowas hier??

$antwort = 'entry.php3?id=Seite49&asid=<#id1>&bsid=<#id2>';

$antwortneu =str_replace ("<#id1>", $_GET['id1'], $antwort);

$antwortneu =str_replace ("<#id2>", $_GET['id2'], $antwortneu);

echo $antwortneu;

wobei das einen aufruf der seite mit den parameter id1 und id2 vorraussetzt, also z.b.

http://myweb.de/getAntwortNeu.php?id1=ID1&id2=ID2

dann kommt dabei raus:

entry.php3?id=Seite49&asid=ID1&bsid=ID2

oder versteh ich das hier alles falsch??

  • Autor

Danke für eure Hilfe ... ich habs nun doch geschafft ... ich meinte sowas:


//Ersetzt Variablen
function replacevars($a,$ {
$da=explode("?",$;

$urlpart1=$da[0]; //erster Teil ohne Parameter
$urlpart2=$da[1]; //ab id1=10...

$para=explode("&",$urlpart2);
for($i=0;$i<(count($para));$i++) {
// Nach 20 Durchläufen abbrechen...
if($i==20) {break;}
$feld = explode("=",$para[$i]);
list($feld,$wert) = split('=', $para[$i]);
$a = str_replace("<#$feld>",$wert,$a);
}
$a = preg_replace("/<#(.*)>/iUs", "", $a);
return $a;
}

//Beispiel
$antwort = 'entry.php?sid=<#id1>&swid=<#id2>&swfid=<#id3>';
$anfrage = '/web/text.php?id1=10&id2=20&id3=30';

//Aufruf d. Funktion und Ausgabe
$antwortneu=replacevars($antwort,$anfrage);
echo $antwortneu;
[/PHP]

Ich danke euch dennoch vielmals !!!

:cool:

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.