if not a string, what?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpHappy
Forum Commoner
Posts: 33
Joined: Wed Oct 26, 2011 1:58 pm

if not a string, what?

Post by phpHappy »

I've never manipulated strings much just replacements or stripslashes because I've always been involved in math programs.
I'm stuck now because I do know string functions but I have a form input that accepts HTML and after checking isset and assigning to a variable I can echo it perfectly but I try strlen or to search strstr or just strpos and it returns false. What is it if not a string?
mikeashfield
Forum Contributor
Posts: 159
Joined: Sat Oct 22, 2011 10:50 am

Re: if not a string, what?

Post by mikeashfield »

do:

Code: Select all

echo gettype($value);
:)
phpHappy
Forum Commoner
Posts: 33
Joined: Wed Oct 26, 2011 1:58 pm

Re: if not a string, what?

Post by phpHappy »

always a function I don't know out there - Thanks

the damn thing echoed string, the variable echoes all the HTML code, but if(strlen($var) > 0) { echo 'yes'; } nothing

Thanks again, though frustrated at least I know that knowing that it WAS a string wasn't crazy as I was beginning to think
phpHappy
Forum Commoner
Posts: 33
Joined: Wed Oct 26, 2011 1:58 pm

Re: if not a string, what?

Post by phpHappy »

Well, throwing things at it and preg_match worked.
mikeashfield
Forum Contributor
Posts: 159
Joined: Sat Oct 22, 2011 10:50 am

Re: if not a string, what?

Post by mikeashfield »

I suggest you take a good look at what's inside the $HTML variable as I think that's what causing you problems. I just did the following with no errors:

Code: Select all

<?php
  $HTML = "<html><head><title>Test 'title'</title></head><body><h1>Testing</h1><p>Testing</p></body></html>";
  echo gettype($HTML)."<br />";
  if (strlen($HTML) > 0) {
      echo "Valid variable length"."<br />";
      echo $HTML;
  } else {
      echo "Invalid variable length";
  }
?>
phpHappy
Forum Commoner
Posts: 33
Joined: Wed Oct 26, 2011 1:58 pm

Re: if not a string, what?

Post by phpHappy »

I knew the string was large but php.net manual says: Note: It is no problem for a string to become very large. PHP imposes no boundary on the size of a string; the only limit is the available memory of the computer on which PHP is running.
phpHappy
Forum Commoner
Posts: 33
Joined: Wed Oct 26, 2011 1:58 pm

Re: if not a string, what?

Post by phpHappy »

Pondering after I posted, I'm going client side to create more hidden inputs that just catch what I need.
Post Reply