If string contains
I need to figure out if a string contains " and if it does, I need to execute something.
Code would look something like this, I don't know PHP very well though.
{
if ($string contains '"')
{
bg = '$string'
}
else
{
bg = "$string"
}
}
Is that possible in php?
teammatt3 posted this at 03:22 — 8th May 2006.
He has: 2,102 posts
Joined: Sep 2003
I found it, but I just found out it won't work for my problem
<?php
$string = 'Hello World!';
if(stristr($string, 'He') === FALSE) {
echo '"earth" not found in string';
}
else
{
echo "It does contain He";
}
?>
CptAwesome posted this at 16:35 — 8th May 2006.
He has: 370 posts
Joined: Dec 2004
Why won't it work for your problem?
teammatt3 posted this at 21:30 — 8th May 2006.
He has: 2,102 posts
Joined: Sep 2003
It is really hard to explain Cpt. But inside the CMS I am using, when ever you type {PAGETITLE} anywhere in the code, the title of the page is displayed. So if I set the $string to equal {PAGETITLE} $string = "{PAGETITLE}" what happens if the page title has a " in it? The code screws up. Is there a way to define a string without " or ' ?
CptAwesome posted this at 22:40 — 8th May 2006.
He has: 370 posts
Joined: Dec 2004
Basically I think the problem is your methodology. You're trying to have the CMS write php code, and that just doesn't work, what you should do, if anything is alter the CMS so that it does an addslashes to whatever is replacing {PAGETITLE} (if you want to do it at all, which again, I don't reccommend. The even better plan is to find out what where PAGETITLE is coming from and use that variable for the $bg, you might have to make it global, but at least it will work.
teammatt3 posted this at 03:25 — 10th May 2006.
He has: 2,102 posts
Joined: Sep 2003
Did exactly that Cpt. It finally works. Thank you soooo much. I was working on that stupid problem for two weeks.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.