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 sprintf '%' als Literal

Empfohlene Antworten

Veröffentlicht

Hallo zusammen,

wie bekomme ich folgenden String mit sprintf formatiert, ohne einen Syntax error?


$s = 'SELECT * FROM tabelle WHERE name LIKE "%H%"';
$s .= ' LIMIT %s, %s'
$a = sprintf( $s, 5, 10);
[/PHP]

Fehlermeldung ist folgende

Warning: sprintf(): Too few arguments in D:\eclipse\workspace\redaxo3_0\redaxo\include\addons\list\classes\class.rexlist.inc.php on line 138

Mir ist klar, dass es am LIKE "%H%" liegt, aber wie muss ich die "%" escapen?

Danke und Gruß,

Markus

---------------------------------------------

UPDATE:

Hmmm, dass scheint die Lösung zu sein...

[PHP]
$s = 'SELECT * FROM tabelle WHERE name LIKE "%%H%%"';
$s .= ' LIMIT %s, %s'
$a = sprintf( $s, 5, 10);

$s = 'SELECT * FROM tabelle WHERE name LIKE "%H%"';

$s .= ' LIMIT %s, %s'

$a = sprintf( $s, 5, 10);

1) es fehlt ein semikolon in der 2. Zeile

2) wie halt escapen in php so geht, backslash, aber

2a) wieso kommt %H% in hochkommata ? sollte auch ohne gehen

3) %s wird als String angesehen und soll auch so eingegeben werden

4) versuchs %d

$a = sprintf ($s, "5", "10");

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.