473,408 Members | 2,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Number 1 is concatenated to the end to array element. How to get rid of this?

103 100+
I am getting strange behavior:

my url: http://localhost/MVCfirst/public/Contact/email/anoth
if i use command
Expand|Select|Wrap|Line Numbers
  1. var_dump($url);
i am getting result:
array(3) { [0]=> string(7) "Contact" [1]=> string(5) "email" [2]=> string(5) "anoth" }
where
Expand|Select|Wrap|Line Numbers
  1. $url=explode('/', filter_var( rtrim($_GET['url'],'/') ), FILTER_SANITIZE_URL);
If i use commands:
Expand|Select|Wrap|Line Numbers
  1. echo '<pre>', print_r($url[0]), '</pre><br>';
  2. echo '<pre>', print_r($url[1]), '</pre><br>';
  3. echo '<pre>', print_r($url[2]), '</pre><br>';
I am getting as a result words:
Contact1
email1
anoth1
Number 1 is concatenated to the end.

How to get rid of 1 concatenated to the end? Because i need word Contact to proceed to controller file and its methods.

Actually i am following online course:
https://www.udemy.com/learn-php-model-view-controller-pattern-php-mvc/#/lecture/2201044

And they make a line in .htaccess:
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

Maybe this line is the reason that 1 is concatenated?
Apr 8 '15 #1

✓ answered by Luuk

http://php.net/manual/en/function.print-r.php:
"When the return parameter is TRUE, this function will return a string. Otherwise, the return value is TRUE. "

so, when you do:
$b="test"; echo "A",print_r($b),"C";

PHP will first print the A
than the value of $b
then the return value of 'print_r($b)'
then the "C"
which is: Atest1C

1 2714
Luuk
1,047 Expert 1GB
http://php.net/manual/en/function.print-r.php:
"When the return parameter is TRUE, this function will return a string. Otherwise, the return value is TRUE. "

so, when you do:
$b="test"; echo "A",print_r($b),"C";

PHP will first print the A
than the value of $b
then the return value of 'print_r($b)'
then the "C"
which is: Atest1C
Apr 8 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: richbl | last post by:
Hello all, I have a question about unserializing a single array element from a serialized array. Can this be done, or must I first unserialize the array, and then access the element? For...
10
by: Noah Spitzer-Williams | last post by:
Hello guys, I'm itinerating through my array using pointers in this fashion: image is unsigned char image do { cout << "image byte is: " << *image << endl;
2
by: csx | last post by:
Hi all, Here's a simple problem I'm having problems with. How do I pass an array element to a function. For instance, values = new values(1, 1,'A',0); values = new values(2, 2,'B',1);...
3
by: Kaz Kylheku | last post by:
Given some class C with array T x, is it possible to get a pointer-to-data-member to one of the elements? &C::x gives us a pointer-to-member-array: T (C::*). But I just want to get a T C::*...
6
by: Herrcho | last post by:
in K&R Chapter 6.3 it mentions two methods to calculate NKEYS. and points out the first one which is to terminate the list of initializers with a null pointer, then loop along keytab until the...
4
by: garak | last post by:
Hi, I got the following problem : I have an defined an Array of different Actions: public PRootActions AllActions = new PRootActions ; I got a dynamic method where all Actions or other...
5
by: jtougas | last post by:
What is the way to the type of an array's elements? Array a = new long { 1, 2, 3 }; Type t = a.GetType(); Console.WriteLine( t.FullName ); This will write "System.Int64", but is not what I'm...
7
by: Michael Bray | last post by:
Let's say I am using reflection to analyze my classes, and I have an array of another class. How do I get the base class that forms the array from a type? public class A { } A MyArray =...
2
by: getteddy | last post by:
hi i am working on array , i am facing a problem in comparing data base element with array element if not (objrs("namephase")=("despArray(ctr,0)+despArray(ctr,3)")) then or If...
13
by: tekinalp67 | last post by:
hi, i am trying to implement a B+ tree. There is no specification in the implementation so i am using arrays to implement the B+ tree. However, there is a problem that i encountered which is I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.