Hướng dẫn php pass variable with spaces - biến php pass có dấu cách

Hình ảnh đầu tiên là mã của tôi. Tôi nhận được ID danh mục "Catid" và tiêu đề danh mục "Cattitle" từ trang trước, tuy nhiên, kết quả không hiển thị chính xác khi có/là một không gian/s trong tiêu đề. Làm cách nào để khắc phục điều này?

Hướng dẫn php pass variable with spaces - biến php pass có dấu cách
The results however does not display correctly when there is/are a space/'s in the title. How do i fix this ?

Bất kỳ sự giúp đỡ nào được đánh giá cao cảm ơn bạn Sam

Hướng dẫn php pass variable with spaces - biến php pass có dấu cách
Thank you Sam

Đã hỏi ngày 20 tháng 1 năm 2015 lúc 12:22Jan 20, 2015 at 12:22

Hướng dẫn php pass variable with spaces - biến php pass có dấu cách

2

Bạn có thể sử dụng các hàm UrlenCode ($ String) và Urldecode ($ String).

cho trường hợp của bạn

$catTitle = urldecode($_GET['catTitle']);

%20 cho thấy bất cứ khi nào có không gian trong url stirng

Đã trả lời ngày 20 tháng 1 năm 2015 lúc 12:29Jan 20, 2015 at 12:29

Hướng dẫn php pass variable with spaces - biến php pass có dấu cách

kamlesh.barkamlesh.barkamlesh.bar

1.72417 Huy hiệu bạc36 Huy hiệu đồng17 silver badges36 bronze badges

1

Biểu tượng "&" là một ví dụ về ký tự đặc biệt trong XML và HTML được gọi là các thực thể và phải được dịch sang "& amp;"

Không sử dụng hàm ăn HTMLEntities để thực hiện dịch:

echo htmlentities($CatTitle); 

Cập nhật: Cũng xem xét rằng URL có thể được giải thích như thể $ _GET ["cattitle"] = "home" và $ _get ["bài viết"] = null. Có thể phải là: cattitle = home%20 &%20garden Trong trường hợp đó bạn có thể muốn sử dụng mã hóa URL trong khi tạo liên kết. Also consider that the URL may be interpreted as if the $_GET["CatTitle"]="Home " and the $_GET[" Articles"] = null. May be it should be: CatTitle=Home%20&%20Garden in which case you may want to use URL encode while genereting the link.

Đã trả lời ngày 20 tháng 1 năm 2015 lúc 12:31Jan 20, 2015 at 12:31

Borjabborjabborjab

10,6K6 Huy hiệu vàng68 Huy hiệu bạc95 Huy hiệu Đồng6 gold badges68 silver badges95 bronze badges

0

Tăng từ email người dùng


TagUI:

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result

PHP:

<?php
echo "argv1 = " . $argv[1];
?>

Làm thế nào để vượt qua đối số với các không gian như trên?

Chuyển những điều trên sẽ gây ra lỗi giống như email trước cho bạn:

  1. Trích dẫn duy nhất gây ra vấn đề
  2. Trích dẫn kép sẽ không hoạt động vì SH/Bash thực hiện thay thế thay đổi

Nếu tôi thay đổi ở trên mà không có trích dẫn duy nhất: chạy php -f php_test1.php thì đây là một chuỗi toàn bộ
run php -f php_test1.php this is one whole string

Nó chỉ trả về "điều này" không đúng. Muốn toàn bộ chuỗi là tham số 'Đây là một chuỗi toàn bộ'

Để được hỗ trợ và tư vấn, xin vui lòng.

2 năm trước

Ẩn danh ¶Pad a string to a certain length with another string

6 năm trước

Gene at swipesy dot com ¶(
    string $string,
    int $length,
    string $pad_string = " ",
    int $pad_type = STR_PAD_RIGHT
): string

11 năm trước

Spudley ¶

15 năm trước

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
7

Fahad Dot Gilani tại Anu Dot Edu Dot Au ¶

Christian Dot Reinecke tại Web Dot de ¶

gtwizard ¶:

5 năm trước

BXI tại Rõa Dot NL ¶

14 năm trướcSTR_PAD_RIGHT,

echo htmlentities($CatTitle); 
9, or
run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
0
. If
echo htmlentities($CatTitle); 
6 is not specified it is assumed to be STR_PAD_RIGHT.

Kirill Fuchs ¶

zubfatal ¶

17 năm trước

matrebatre ¶str_pad() example

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
3

Kari " HaProg " Sderholm ¶

13 năm trước

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
4

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
5

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
6

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
7

Email chấm riêng tại optusnet dot com dot au ¶

Bob [at] Bobarmadillo [dot] com ¶

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
8

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
9

<?php
echo "argv1 = " . $argv[1];
?>
0

<?php
echo "argv1 = " . $argv[1];
?>
1

<?php
echo "argv1 = " . $argv[1];
?>
2

<?php
echo "argv1 = " . $argv[1];
?>
3

<?php
echo "argv1 = " . $argv[1];
?>
4

<?php
echo "argv1 = " . $argv[1];
?>
0

<?php
echo "argv1 = " . $argv[1];
?>
6

<?php
echo "argv1 = " . $argv[1];
?>
2

<?php
echo "argv1 = " . $argv[1];
?>
8

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
7

Wes tại nospamplsexample dot org ¶

7 năm trước

$string0

$string1

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
7

Qeremy [atta] gmail [dotta] com ¶

9 năm trước

$string3

$string4

$string5

$string6

Pestilenc tại hotmail dot com

20 năm trước

$string7

$string8

$string9

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
7

MCINP ¶

7 năm trước

$length1

$length2

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
7

Qeremy [atta] gmail [dotta] com ¶

9 năm trước

$length4

$length5

$length6

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
7

Pestilenc tại hotmail dot com

20 năm trước

$length8

$length9

$pad_string0

$pad_string1

$pad_string2

$pad_string3

$pad_string4

MCINP ¶

Bob [at] Bobarmadillo [dot] com ¶

$pad_string5

$pad_string6

$pad_string7

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
7

19 năm trước

Borszczuk

$pad_string9

$pad_type0

$pad_type1

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
7

1 tháng trước

Neo_selen ¶

$pad_type3

$pad_type4

$pad_type5

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
7

2 năm trước

Ẩn danh ¶

$pad_type7

$pad_type8

$pad_type9

6 năm trước

Gene at swipesy dot com ¶

19 năm trước

STR_PAD_RIGHT1

STR_PAD_RIGHT2

STR_PAD_RIGHT3

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
7

Christian Dot Reinecke tại Web Dot de ¶

15 năm trước

STR_PAD_RIGHT5

STR_PAD_RIGHT6

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
7

gtwizard ¶

5 năm trước

STR_PAD_RIGHT8

STR_PAD_RIGHT9

string0

string1

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
7

BXI tại Rõa Dot NL ¶

14 năm trước

string3

string4

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
7

Kirill Fuchs ¶

5 năm trước

string6

string7

string8

string9

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
7

BXI tại Rõa Dot NL ¶

14 năm trước

echo htmlentities($CatTitle); 
01

echo htmlentities($CatTitle); 
02

echo htmlentities($CatTitle); 
03

Kirill Fuchs ¶

14 năm trước

echo htmlentities($CatTitle); 
04

echo htmlentities($CatTitle); 
05

echo htmlentities($CatTitle); 
06

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
7

Kirill Fuchs ¶

zubfatal ¶

echo htmlentities($CatTitle); 
08

echo htmlentities($CatTitle); 
09

echo htmlentities($CatTitle); 
10

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
7

17 năm trước

14 năm trước

echo htmlentities($CatTitle); 
12

echo htmlentities($CatTitle); 
13

echo htmlentities($CatTitle); 
14

echo htmlentities($CatTitle); 
15

Kirill Fuchs ¶

zubfatal ¶

echo htmlentities($CatTitle); 
16

echo htmlentities($CatTitle); 
17

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
7

17 năm trước

matrebatre ¶

echo htmlentities($CatTitle); 
19

echo htmlentities($CatTitle); 
20

echo htmlentities($CatTitle); 
21

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
7

Kari " HaProg " Sderholm ¶

14 năm trước

echo htmlentities($CatTitle); 
23

echo htmlentities($CatTitle); 
24

echo htmlentities($CatTitle); 
25

echo htmlentities($CatTitle); 
26

echo htmlentities($CatTitle); 
27

Kirill Fuchs ¶

zubfatal ¶

echo htmlentities($CatTitle); 
28

echo htmlentities($CatTitle); 
29

17 năm trước

matrebatre ¶

5 năm trước

echo htmlentities($CatTitle); 
31

echo htmlentities($CatTitle); 
32

echo htmlentities($CatTitle); 
33

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
7

BXI tại Rõa Dot NL ¶

matrebatre ¶

echo htmlentities($CatTitle); 
35

echo htmlentities($CatTitle); 
36

echo htmlentities($CatTitle); 
37

echo htmlentities($CatTitle); 
38

run php -f php_test1.php 'this is one whole string'
result = run_result
echo "result = " + result
7

Kari " HaProg " Sderholm ¶

Một tên biến chỉ có thể chứa các ký tự âm alpha và dấu gạch dưới (a-z, a-z, 0-9 và _) tên biến là nhạy cảm trường hợp (tuổi, tuổi và tuổi là ba biến khác nhau) không có giới hạn về độ dài của độ dài củaTên biến.Một tên biến không thể chứa khoảng trắng.A variable name cannot contain spaces.

Tên biến nào sau đây là hợp lệ trong PHP?

Một tên biến phải bắt đầu bằng một chữ cái hoặc ký tự dấu gạch dưới.Một tên biến không thể bắt đầu với một số.Một tên biến chỉ có thể chứa các ký tự alpha-numeric và các tên biến (A-Z, 0-9 và _) là nhạy cảm trường hợp ($ Age và $ Age là hai biến khác nhau). A variable name cannot start with a number. A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) Variable names are case-sensitive ( $age and $AGE are two different variables)