Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 更换从外部div拉出的连杆部分_Php_Url_Str Replace - Fatal编程技术网

Php 更换从外部div拉出的连杆部分

Php 更换从外部div拉出的连杆部分,php,url,str-replace,Php,Url,Str Replace,我有以下代码来提取外部div的内容并显示在我的网页上: 使输出链接中的第一个字母大写的第一个som样式: <style> h1:first-letter {text-transform: uppercase;} /* make first letter in link upper-case */ h1 {margin-bottom: -15px; font-size:1.2em;} p {margin-bottom: 5px;} a {text-decoration: none;}

我有以下代码来提取外部div的内容并显示在我的网页上:

使输出链接中的第一个字母大写的第一个som样式:

<style>
h1:first-letter {text-transform: uppercase;} /* make first letter in link upper-case */
h1 {margin-bottom: -15px; font-size:1.2em;}
p {margin-bottom: 5px;}
a {text-decoration: none;}
</style>
我还编辑了原始代码,以反映我所做的最新更改


谢谢

您应该影响
str\u replace

$content = str_replace('./opening', 'https://ekstern.vuq.visma.com/ra_recruitment/opening', $content);
使用preg_替换方法:

$url = '<a href="./opening;jsessionid=E2A19018E967B4771224A9FA515AFBC0?0-1.ILinkListener-content-contentPanel-openings~view~container-openings~view-0-details"><span style="font-weight:bold;">fagarbeider</span></a>';

// What do you want to replace ?
$patterns = array(
    '#\./opening;jsessionid=.*\?#',
    '#<a href=#',
    '#span(.*?)>#'
);

// By What ?
$replaces = array(
    'https://ekstern.vuq.visma.com/ra_recruitment/opening?',
    '<a target="_blank" href=',
    'h1>'
);

echo preg_replace($patterns, $replaces, $url);
$url='';
//你想替换什么?
$patterns=数组(
“#\./开始;JSSessionId=.*\?#”,
“#

我让代码简单而愚蠢。


<?php
$url = 'https://ekstern.vuq.visma.com/ra_recruitment/';
$content = file_get_contents($url);
$content1=str_replace('./opening', 'https://ekstern.vuq.visma.com/ra_recruitment/opening', $content);
$first_step = explode( '<div id="ide">' ,  $content1 );
$second_step = explode("</div>" , $first_step[1] );

echo $second_step[0], $second_step[1], $second_step[2], $second_step[3], $second_step[4], $second_step[5], $second_step[6];
?>  

谢谢,这解决了问题!但随后又出现了一个新问题。似乎从原始页面提取的url包含一个
jsessionid
字符串,我需要删除该字符串才能正常工作。添加了
str replace
后提取的url:
https://ekstern.vuq.visma.com/ra_recruitment/opening;jsessionid=48311227429D90F89603CFA1D3EF3859?0-1.ILinkListener内容面板开口~view~容器开口~view-0-details
我需要它是什么:
https://ekstern.vuq.visma.com/ra_recruitment/opening?0-1.ILinkListener内容面板开口~view~容器开口~view-0-details
有什么有效的方法来解决这个问题吗?你能告诉我吗它显示您的帖子并显示您的原始数据($content from file\u get\u contents)还有你需要的原始输出?我认为有一种更优雅的方式来达到想要的结果,只需使用preg_replace。谢谢@bang,我在原始帖子中编辑了代码,并添加了原始rata。我想我不会让它像我想要的那样工作,但如果它可以优化,那将是完美的。谢谢,这也很有效,我编辑了o新代码的原始帖子。
$url = '<a href="./opening;jsessionid=E2A19018E967B4771224A9FA515AFBC0?0-1.ILinkListener-content-contentPanel-openings~view~container-openings~view-0-details"><span style="font-weight:bold;">fagarbeider</span></a>';

// What do you want to replace ?
$patterns = array(
    '#\./opening;jsessionid=.*\?#',
    '#<a href=#',
    '#span(.*?)>#'
);

// By What ?
$replaces = array(
    'https://ekstern.vuq.visma.com/ra_recruitment/opening?',
    '<a target="_blank" href=',
    'h1>'
);

echo preg_replace($patterns, $replaces, $url);
<?php
$url = 'https://ekstern.vuq.visma.com/ra_recruitment/';
$content = file_get_contents($url);
$content1=str_replace('./opening', 'https://ekstern.vuq.visma.com/ra_recruitment/opening', $content);
$first_step = explode( '<div id="ide">' ,  $content1 );
$second_step = explode("</div>" , $first_step[1] );

echo $second_step[0], $second_step[1], $second_step[2], $second_step[3], $second_step[4], $second_step[5], $second_step[6];
?>