PHP / HTML是否有办法在浏览器中打开链接?

发布于 2025-01-27 09:50:04 字数 369 浏览 2 评论 0原文

抱歉,如果问题有些混乱,我的问题是与我当前的代码:

$pattern = '/(([\w+]+\:\/\/)?([\w\d-]+\.)*[\w-]+[\.\:]\w+([\/\?\=\&\#.]?[\w-]+)*\/?)/m';
            
$str = file_get_contents('notiz.txt');
echo nl2br (preg_replace($pattern, "<a href='?url=$1' >$1</a>", $str))

每个链接都在PHP桌面应用程序中打开,但是我希望它在浏览器中打开(Edge,Chrome等)。我仍然是PHP和HTML的新手。

编辑:这是

Sorry if the question is a bit confusing, my problem is that with my current code:

$pattern = '/(([\w+]+\:\/\/)?([\w\d-]+\.)*[\w-]+[\.\:]\w+([\/\?\=\&\#.]?[\w-]+)*\/?)/m';
            
$str = file_get_contents('notiz.txt');
echo nl2br (preg_replace($pattern, "<a href='?url=$1' >$1</a>", $str))

every link is opened in the PHP desktop app, but i want it to open in the browser (Edge, Chrome, whatever). I'm still pretty new to PHP and html.

Edit: Here's a screenshot ofenter image description here PHP Desktop Chrome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

命硬 2025-02-03 09:50:04

在浏览器中,您需要一些帮助形式JavaScript。仅将脚本放在下面
&lt;/body&gt;标签。

<script>
            window.addEventListener('load', openLinks, false);
            function openLinks() {
                document.querySelectorAll('A').forEach((a) => {
                    window.open(a.href);

                });
            }
        </script>

加载页面并渲染函数 openlinks 正在寻找文档中的所有&gt; a&gt; 标签,并将打开每个带有 window.open()的新标签。

In the browser you will need some help form JavaScript. Put the script below just
before the </body> tag.

<script>
            window.addEventListener('load', openLinks, false);
            function openLinks() {
                document.querySelectorAll('A').forEach((a) => {
                    window.open(a.href);

                });
            }
        </script>

When the page is loaded and rendered the function OpenLinks is looking for all <A> tags in your document and will open each one in a new tab with window.open().

躲猫猫 2025-02-03 09:50:04

经过一些朋友的研究和帮助,我找到了一种有效的方法。我的问题可能也令人困惑。这是工作代码:

if(isset($_REQUEST['url'])): 
                $cmd=sprintf( '"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -window-size=1280,780 --app=%s', $_REQUEST['url'] );
                exec( $cmd );
            endif;

这确保在新窗口中使用Google Chrome在我单击时打开链接。
无论如何,感谢您的帮助。

After some research and help of a friend i found a way that works. My question was probably confusing too. Here's the working code:

if(isset($_REQUEST['url'])): 
                $cmd=sprintf( '"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -window-size=1280,780 --app=%s', $_REQUEST['url'] );
                exec( $cmd );
            endif;

This makes sure to use Google Chrome in a new window to open the link when i click on it.
Thanks for all your help anyways.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文