M
M
mts20502016-03-11 19:05:38
PHP
mts2050, 2016-03-11 19:05:38

How to display certain text from memory (php)?

Please tell me how to write php.
Code: <?php echo $category['href']; ?>
Outputs: /index.php?route=product/category&path=60
How to write php to display: just the number 60?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
A
Andrey, 2016-03-11
@mts2050

<?php echo str_replace('.png', '', $category['href']); ?>

V
Viktor, 2016-03-11
@master2016

It's easier that way. This is the easiest way.
<?php echo '60'; ?>

M
MaEcTPo, 2016-03-11
@MaEcTPo

How can you even waste your time asking such questions?
From memory! It's "from the value of the variable/array", not from memory!

$testString = '/index.php?route=product/category&path=60';
parse_str(parse_url($testString, PHP_URL_QUERY), $params);
print_r($params);

Conclusion:
Array
(
    [route] => product/category
    [path] => 60
)

V
Vitaly Artemyev, 2016-03-11
@Vitaly48

preg_match("/\d+/", $category['href'], $match);
echo $match[0];

S
Silm, 2016-03-12
@Silm

"remove certain text from memory" whatoo... you need to process the string, get part of it... what other memory
php.net/manual/ru/function.preg-replace.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question