$string = 'http://site.com/category/1/news/2134/'; // '1' is dynamic
How do I change 1to any number I want?
1
It is not possible to call parts of a string, its just a text variable.
This can be done with some true regex.
$string = preg_replace('~(?<=category/)[0-9]+(?=/news)~', '56', $string);
This replaces the number with 56.
This approach uses a regex with assertions .
$array = explode('/',$string); $array[4] = '666'; $string = implode('/',$array);
[edit] @Power downvoting, what seems to be a problem with this approach?
Without further information, my best guess about your problem:
<?php $string = 'http://site.com/category/' . $yourNumberHere . '/news/2134/'; ?>
Source: https://habr.com/ru/post/1763079/More articles:https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1763074/read-only-rather-small-database-ways-to-optimise&usg=ALkJrhi6YmwWaDFv9kQV6qS5Z84T7A9ipwGit vs SVN: ΠΌΠΎΠ³Ρ Π»ΠΈ Ρ ΠΈΠΌΠ΅ΡΡ ΠΎΠ΄Π½ΠΎ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠ΅ Π² ΠΈΡΡΠΎΡΠΈΠΈ Π΄Π»Ρ Π½Π΅ΡΠΊΠΎΠ»ΡΠΊΠΈΡ Π²Π΅ΡΠ²Π΅ΠΉ? - gituse variable for atomic variables - javaNew nullpointerexception activity - androidMySQL: one or more rows? - databasehow to automatically add a new file in SVN in eclipse - javaΠΠ°ΠΊ ΠΎΡΠΏΡΠ°Π²ΠΈΡΡ ΠΏΡΡΠΌΠΎΠ΅ ΡΠΎΠΎΠ±ΡΠ΅Π½ΠΈΠ΅ Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΠ΅ΠΌ Π±ΠΈΠ±Π»ΠΈΠΎΡΠ΅ΠΊΠΈ Abraham oauth - phpSQL sql profile template file format - sql-serverΠΠ½ΡΠ΅Π³ΡΠ°ΡΠΈΡ R ΠΈ Flex - flexGlassfish vhost to serve only static content. Disconnect a session, how? - glassfishAll Articles