MyBB Community Forums

Full Version: PHP - 2 Values to 1 Variable?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
What I posted was a shot in the dark. I don't understand what your script does.
PMed.
how about:

<?php
$variable .= "Value1";
$variable .= "Value2";
echo $variable;

Does that work?
(2009-09-07, 06:37 AM)magicstuff Wrote: [ -> ]Does that work?

No.

Zash, from what I understand about your script, having 2 variables as one really doesn't pay off. A nice technique, but pointless. Explode is useful when you have lots of information that you want to put into a variable (and you know where it is so it's easy to retrieve), but it's just as simple to leave it as array values.

In the code you posted a few up from here, you're using a plain $linkback. Because you've exploded it, it is now an array. It should look something like this:

Array(
     [0] => $cfg['scan_needle']
     [1] => $cfg['scan_needle_2']
)

So, for your script to work, you will need to put either $linkback[0] or $linkback[1].
Yea that's not my goal. I need it so that linkback will represent both. Xiofire said this is right:

$linkback = cfg['scan_needle'];
$linkback .= cfg['scan_needle_2']

If this doesn't work then I may be forced to just set up some if else statement Undecided
(2009-09-07, 12:00 PM)Zash Wrote: [ -> ]Yea that's not my goal. I need it so that linkback will represent both. Xiofire said this is right:

$linkback = cfg['scan_needle'];
$linkback .= cfg['scan_needle_2']

If this doesn't work then I may be forced to just set up some if else statement Undecided

Doing that, if cfg['scan_needle'] =

www.example.com

and cfg['scan_needle_2'] =

www.test.com

then $linkback would end up being

www.example.comwww.test.com

would it not...??
(2009-09-07, 12:00 PM)Zash Wrote: [ -> ]Yea that's not my goal. I need it so that linkback will represent both. Xiofire said this is right:

$linkback = cfg['scan_needle'];
$linkback .= cfg['scan_needle_2']

If this doesn't work then I may be forced to just set up some if else statement Undecided
Nope didn't work. I'm gonna try an if else...
I got it Big Grin

Just had to change:

    if (!$errors && $cfg['scan'])
    {
        $found_needle = false;    
        $url_2 = @parse_url($hint);
        if (isset($url_2['host']) && $url_2['host'] == $url['host'])
        {
            $tmp = "http://".$url['host'];
            if (isset($url_2['path']))
                $tmp .= $url_2['path'];
            if (isset($url_2['query']))
                $tmp .= '?'.$url_2['query'];
            $data = file_get_contents($tmp);
            if (stristr($data, $cfg['scan_needle']) !== false)
                $found_needle = true;
        }
        if (!$found_needle)
        {
            $scanner = new Scanner();
            $scanner->init($proxy, $cfg['scan_needle']);
            $found_needle = $scanner->scan($cfg['scan_timeout']);
        }
        if (!$found_needle)
            $errors[] = 'We can\'t find a link back to us on your website.'; 
to
    if (!$errors && $cfg['scan'])
    {
        $found_needle = false;    
        $url_2 = @parse_url($hint);
        if (isset($url_2['host']) && $url_2['host'] == $url['host'])
        {
            $tmp = "http://".$url['host'];
            if (isset($url_2['path']))
                $tmp .= $url_2['path'];
            if (isset($url_2['query']))
                $tmp .= '?'.$url_2['query'];
            $data = file_get_contents($tmp);
            if (stristr($data, $cfg['scan_needle']) !== false)
                $found_needle = true;
        }
        if (!$found_needle)
        {
            $scanner = new Scanner();
            $scanner->init($proxy, $cfg['scan_needle']);
            $found_needle = $scanner->scan($cfg['scan_timeout']);
        }
        if (!$found_needle)
        {
            $scanner = new Scanner();
            $scanner->init($proxy, $cfg['scan_needle_2']);
            $found_needle = $scanner->scan($cfg['scan_timeout']);
        }
        if (!$found_needle)
            $errors[] = 'We can\'t find a link back to us on your website.'; 
Just needed add a second check Big Grin
Assuming this :
$cfg['scan_needle'] = '<a href="http://MyDomain.com"|"<a href="http://www.MyDomain.com"';

Then your code would be better like this :

if (!$errors && $cfg['scan'])
    {
        $needles = explode('|', $cfg['scan_needle']);
        $found_needle = false;    
        $url_2 = @parse_url($hint);
        if (isset($url_2['host']) && $url_2['host'] == $url['host'])
        {
            $tmp = "http://".$url['host'];
            if (isset($url_2['path']))
                $tmp .= $url_2['path'];
            if (isset($url_2['query']))
                $tmp .= '?'.$url_2['query'];
            $data = file_get_contents($tmp);
            foreach($needles as $needle){
               if (stristr($data, $needle) !== false){
                 $found_needle = true;
                 break;
               }
            }
        }
        if (!$found_needle)
            $errors[] = 'We can\'t find a link back to us on your website.'; 

And you would be able to add many other needles afterward as needed.

P.S. I wonder how you could solve your own customers issues with their scripts as customer support...
(2009-09-07, 04:16 PM)exdiogene Wrote: [ -> ]Assuming this :
$cfg['scan_needle'] = '<a href="http://MyDomain.com"|"<a href="http://www.MyDomain.com"';

Then your code would be better like this :

if (!$errors && $cfg['scan'])
    {
        $needles = explode('|', $cfg['scan_needle']);
        $found_needle = false;    
        $url_2 = @parse_url($hint);
        if (isset($url_2['host']) && $url_2['host'] == $url['host'])
        {
            $tmp = "http://".$url['host'];
            if (isset($url_2['path']))
                $tmp .= $url_2['path'];
            if (isset($url_2['query']))
                $tmp .= '?'.$url_2['query'];
            $data = file_get_contents($tmp);
            foreach($needles as $needle){
               if (stristr($data, $needle) !== false){
                 $found_needle = true;
                 break;
               }
            }
        }
        if (!$found_needle)
            $errors[] = 'We can\'t find a link back to us on your website.'; 

And you would be able to add many other needles afterward as needed.

P.S. I wonder how you could solve your own customers issues with their scripts as customer support...
I have a basic knowledge of PHP, and I'm learning. Plus, I am not the only one, I do get help Smile
Why not just use an array? :| instead of explode and all that stuff.

Just do
$cfg['scan_needle'] = array('MyDomain.com', 'www.MyDomain.com');
And then just
foreach($cfg['scan_needle'] as $needle)
Pages: 1 2 3