Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

strpos not working php5.0.5

Status
Not open for further replies.

tewari68

Programmer
Jan 25, 2005
87
US
Hi,
I am seeing a strange behaviour regarding strpos function
using php5.0.5/apache2
In the following code
Code:
function Clean_header_from($header)
	{

	if(strpos($header,"<") === 0)
		{
		$clean_head=str_replace("<","",$header);
		$clean_head=str_replace(">","",$clean_head);
		}
	elseif(strpos($header,"<") > 0)
		{
		
		$name_pos=strpos($header,"<");
		$name=substr($header,0,$name_pos);

		$email_pos=strlen($name)+1;
		$email=substr($header,$email_pos);
		$email=str_replace("<","",$email);
		$email=str_replace(">","",$email);
		//$email=str_replace("From:", "", $email);
		$name=str_replace("\"","",$name);
		$clean_head=$email;
		//.";".$name;
		}
	else
		$clean_head=$header.";";

	return $clean_head;
	}
if i call this function from the main program and pass the $header value it doesn't do anything falls to the default else condition
however if I define $header inside the function that it works and gives the results as desired.
Ex.
Code:
if I call this function like and pass it a value 
$x = new class();->instantiating the class inside which the function is defined
$new = $x->Clean_header_from($header);=>where $header = '"name" <user@domain.tld'
nothing happens and falls to the default else condition
However if I define $header inside the function  as $header = '"name" <user@domain.tld>'
I get the name and user@domain.tld values.
Appreciate any help in this regards.
Thanks,
 
If strpos() works as expected when you hardcode the value in the function, but not when the value is passed in, I'd be more inclined to look at your value-passing.

When you pass the value into the function as a paramenter, have you verified that the value passed is what you expect?



Want the best answers? Ask the best questions! TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top